52 lines
1.8 KiB
C#
52 lines
1.8 KiB
C#
using Godot;
|
|
|
|
namespace PolarBears.PlayerControllerAddon;
|
|
|
|
public partial class MantleSystem: Node3D
|
|
{
|
|
[Export(PropertyHint.Range, "0,2,0.1,or_greater")]
|
|
public float MantleEndLocationDistanceFromWall { get; set; } = 1f;
|
|
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
|
|
public float MantleHeightCastStart { get; set; } = 2f;
|
|
[Export(PropertyHint.Range, "0,10,0.01,suffix:m,or_greater")]
|
|
public float MaxStepHeight = 0.5f;
|
|
|
|
private Node3D _head;
|
|
private ShapeCast3D _wallInFrontCast3D;
|
|
private ShapeCast3D _mantleCast3D;
|
|
|
|
public void Init(ShapeCast3D wallInFrontCast3D, Node3D head, ShapeCast3D mantleCast3D)
|
|
{
|
|
_wallInFrontCast3D = wallInFrontCast3D;
|
|
_head = head;
|
|
_mantleCast3D = mantleCast3D;
|
|
}
|
|
|
|
public Vector3 CheckWallInFront()
|
|
{
|
|
_wallInFrontCast3D.SetRotation(new Vector3(
|
|
_wallInFrontCast3D.Rotation.X,
|
|
_head.Rotation.Y,
|
|
_wallInFrontCast3D.Rotation.Z));
|
|
|
|
if (!_wallInFrontCast3D.IsColliding())
|
|
{
|
|
return Vector3.Zero;
|
|
}
|
|
|
|
Vector3 collisionPoint = _wallInFrontCast3D.GetCollisionPoint(0);
|
|
Vector3 horizontalEndLocation = collisionPoint - _wallInFrontCast3D.GetCollisionNormal(0) * MantleEndLocationDistanceFromWall;
|
|
Vector3 shapeCastStartLocation = horizontalEndLocation + Vector3.Up * MantleHeightCastStart;
|
|
|
|
_mantleCast3D.SetGlobalPosition(shapeCastStartLocation);
|
|
Vector3 targetLocation = Vector3.Down * MantleHeightCastStart + Vector3.Up * MaxStepHeight;
|
|
_mantleCast3D.SetTargetPosition(targetLocation);
|
|
|
|
if (!_mantleCast3D.IsColliding())
|
|
{
|
|
return Vector3.Zero;
|
|
}
|
|
return _mantleCast3D.GetCollisionPoint(0);
|
|
}
|
|
}
|