gd: mantle end location system
This commit is contained in:
@ -4,29 +4,48 @@ namespace PolarBears.PlayerControllerAddon;
|
||||
|
||||
public partial class MantleSystem: Node3D
|
||||
{
|
||||
private RayCast3D _wallInFrontRaycast3D;
|
||||
[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(RayCast3D wallInFrontRaycast3D, Node3D head)
|
||||
public void Init(ShapeCast3D wallInFrontCast3D, Node3D head, ShapeCast3D mantleCast3D)
|
||||
{
|
||||
_wallInFrontRaycast3D = wallInFrontRaycast3D;
|
||||
_wallInFrontCast3D = wallInFrontCast3D;
|
||||
_head = head;
|
||||
_mantleCast3D = mantleCast3D;
|
||||
}
|
||||
|
||||
public void CheckWallInFront()
|
||||
public Vector3 CheckWallInFront()
|
||||
{
|
||||
_wallInFrontRaycast3D.SetRotation(new Vector3(
|
||||
_wallInFrontRaycast3D.Rotation.X,
|
||||
_wallInFrontCast3D.SetRotation(new Vector3(
|
||||
_wallInFrontCast3D.Rotation.X,
|
||||
_head.Rotation.Y,
|
||||
_wallInFrontRaycast3D.Rotation.Z));
|
||||
_wallInFrontCast3D.Rotation.Z));
|
||||
|
||||
var collider = _wallInFrontRaycast3D.GetCollider();
|
||||
if (collider == null)
|
||||
if (!_wallInFrontCast3D.IsColliding())
|
||||
{
|
||||
return;
|
||||
return Vector3.Zero;
|
||||
}
|
||||
|
||||
GD.Print(_wallInFrontRaycast3D.GetCollisionPoint());
|
||||
GD.Print(_wallInFrontRaycast3D.GetCollisionNormal());
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +59,8 @@ public partial class PlayerController : CharacterBody3D
|
||||
|
||||
RayCast3D stairsBelowRayCast3D = GetNode<RayCast3D>("StairsBelowRayCast3D");
|
||||
RayCast3D stairsAheadRayCast3D = GetNode<RayCast3D>("StairsAheadRayCast3D");
|
||||
RayCast3D wallInFrontRaycast3D = GetNode<RayCast3D>("WallInFrontRayCast3D");
|
||||
ShapeCast3D wallInFrontCast3D = GetNode<ShapeCast3D>("WallInFrontCast3D");
|
||||
ShapeCast3D mantleCast3D = GetNode<ShapeCast3D>("MantleCast3D");
|
||||
|
||||
Node3D cameraSmooth = GetNode<Node3D>("Head/CameraSmooth");
|
||||
|
||||
@ -93,7 +94,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
StairsSystem.Init(stairsBelowRayCast3D, stairsAheadRayCast3D, cameraSmooth);
|
||||
|
||||
MantleSystem = GetNode<MantleSystem>("MantleSystem");
|
||||
MantleSystem.Init(wallInFrontRaycast3D, Head);
|
||||
MantleSystem.Init(wallInFrontCast3D, Head, mantleCast3D);
|
||||
|
||||
CapsuleCollider = GetNode<CapsuleCollider>("CapsuleCollider");
|
||||
|
||||
|
@ -23,7 +23,6 @@ public partial class StairsSystem: Node3D
|
||||
_stairsBelowRayCast3D = stairsBelowRayCast3D;
|
||||
_stairsAheadRayCast3D = stairsAheadRayCast3D;
|
||||
_cameraSmooth = cameraSmooth;
|
||||
|
||||
}
|
||||
|
||||
public bool WasSnappedToStairsLastFrame() { return _snappedToStairsLastFrame; }
|
||||
|
Reference in New Issue
Block a user