gd,fix: fixed a bug where the dash could mantle you nowhere. Automatic mantle at the end of dash.

This commit is contained in:
2025-05-27 15:15:07 +02:00
parent 1d8a8c7423
commit d8a1604af9
6 changed files with 139 additions and 63 deletions

View File

@ -1,13 +1,14 @@
using Godot;
using System;
using Godot;
using RustyOptions;
namespace PolarBears.PlayerControllerAddon;
public partial class MantleSystem: Node3D
{
[Export(PropertyHint.Range, "0,2,0.1,or_greater")]
[Export(PropertyHint.Range, "0,2,0.1,suffix:m,or_greater")]
public float MantleEndLocationDistanceFromWall { get; set; } = 1f;
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
[Export(PropertyHint.Range, "0,10,0.1,suffix:m,or_greater")]
public float MantleHeightCastStart { get; set; } = 2f;
[Export(PropertyHint.Range, "0,10,0.01,suffix:m,or_greater")]
public float MaxStepHeight = 0.5f;
@ -15,15 +16,16 @@ public partial class MantleSystem: Node3D
private Node3D _head;
private ShapeCast3D _wallInFrontCast3D;
private ShapeCast3D _mantleCast3D;
private RayCast3D _mantleCheckCast3D;
public void Init(ShapeCast3D wallInFrontCast3D, Node3D head, ShapeCast3D mantleCast3D)
public void Init(Node3D head)
{
_wallInFrontCast3D = wallInFrontCast3D;
_head = head;
_mantleCast3D = mantleCast3D;
_wallInFrontCast3D = GetNode<ShapeCast3D>("WallInFrontCast3D");
_mantleCast3D = GetNode<ShapeCast3D>("MantleCast3D");
}
public Result<Vector3, string> CheckWallInFront()
public Option<Vector3> FindMantleInFrontOfPlayer()
{
_wallInFrontCast3D.SetRotation(new Vector3(
_wallInFrontCast3D.Rotation.X,
@ -32,17 +34,25 @@ public partial class MantleSystem: Node3D
if (!_wallInFrontCast3D.IsColliding())
{
return Result.Err<Vector3, string>("No collision found");
return Option<Vector3>.None;
}
var collisionPoint = _wallInFrontCast3D.GetCollisionPoint(0);
var horizontalEndLocation = collisionPoint - _wallInFrontCast3D.GetCollisionNormal(0) * MantleEndLocationDistanceFromWall;
var collisionNormal = _wallInFrontCast3D.GetCollisionNormal(0);
return FindMantleLocationAtPoint(collisionPoint, collisionNormal);
}
public Option<Vector3> FindMantleLocationAtPoint(Vector3 point, Vector3 wallNormal)
{
var horizontalEndLocation = point - wallNormal * MantleEndLocationDistanceFromWall;
var shapeCastStartLocation = horizontalEndLocation + Vector3.Up * MantleHeightCastStart;
_mantleCast3D.SetGlobalPosition(shapeCastStartLocation);
var targetLocation = Vector3.Down * MantleHeightCastStart + Vector3.Up * MaxStepHeight;
_mantleCast3D.SetTargetPosition(targetLocation);
return _mantleCast3D.IsColliding() ? Result.Ok(_mantleCast3D.GetCollisionPoint(0)) : Result.Err<Vector3, string>("No collision found");
if (_mantleCast3D.IsColliding() && _mantleCast3D.GetCollisionNormal(0).Y > 0.9f)
return Option.Some(_mantleCast3D.GetCollisionPoint(0));
return Option<Vector3>.None;
}
}