diff --git a/Movement tests.csproj b/Movement tests.csproj
index b37b5b8..41a8458 100644
--- a/Movement tests.csproj
+++ b/Movement tests.csproj
@@ -10,4 +10,7 @@
+
+
+
\ No newline at end of file
diff --git a/player_controller/Scripts/MantleSystem.cs b/player_controller/Scripts/MantleSystem.cs
index 90ae75d..4f806a3 100644
--- a/player_controller/Scripts/MantleSystem.cs
+++ b/player_controller/Scripts/MantleSystem.cs
@@ -1,4 +1,5 @@
using Godot;
+using RustyOptions;
namespace PolarBears.PlayerControllerAddon;
@@ -22,7 +23,7 @@ public partial class MantleSystem: Node3D
_mantleCast3D = mantleCast3D;
}
- public Vector3 CheckWallInFront()
+ public Result CheckWallInFront()
{
_wallInFrontCast3D.SetRotation(new Vector3(
_wallInFrontCast3D.Rotation.X,
@@ -31,21 +32,17 @@ public partial class MantleSystem: Node3D
if (!_wallInFrontCast3D.IsColliding())
{
- return Vector3.Zero;
+ return Result.Err("No collision found");
}
- Vector3 collisionPoint = _wallInFrontCast3D.GetCollisionPoint(0);
- Vector3 horizontalEndLocation = collisionPoint - _wallInFrontCast3D.GetCollisionNormal(0) * MantleEndLocationDistanceFromWall;
- Vector3 shapeCastStartLocation = horizontalEndLocation + Vector3.Up * MantleHeightCastStart;
+ var collisionPoint = _wallInFrontCast3D.GetCollisionPoint(0);
+ var horizontalEndLocation = collisionPoint - _wallInFrontCast3D.GetCollisionNormal(0) * MantleEndLocationDistanceFromWall;
+ var shapeCastStartLocation = horizontalEndLocation + Vector3.Up * MantleHeightCastStart;
_mantleCast3D.SetGlobalPosition(shapeCastStartLocation);
- Vector3 targetLocation = Vector3.Down * MantleHeightCastStart + Vector3.Up * MaxStepHeight;
+ var targetLocation = Vector3.Down * MantleHeightCastStart + Vector3.Up * MaxStepHeight;
_mantleCast3D.SetTargetPosition(targetLocation);
- if (!_mantleCast3D.IsColliding())
- {
- return Vector3.Zero;
- }
- return _mantleCast3D.GetCollisionPoint(0);
+ return _mantleCast3D.IsColliding() ? Result.Ok(_mantleCast3D.GetCollisionPoint(0)) : Result.Err("No collision found");
}
}
diff --git a/player_controller/Scripts/PlayerController.cs b/player_controller/Scripts/PlayerController.cs
index 61eae07..ad67f87 100644
--- a/player_controller/Scripts/PlayerController.cs
+++ b/player_controller/Scripts/PlayerController.cs
@@ -123,8 +123,7 @@ public partial class PlayerController : CharacterBody3D
public override void _PhysicsProcess(double delta)
{
- MantleSystem.CheckWallInFront();
-
+ var mantleLocationResult = MantleSystem.CheckWallInFront();
if (isOnFloorCustom())
{
_lastFrameWasOnFloor = Engine.GetPhysicsFrames();
@@ -145,24 +144,33 @@ public partial class PlayerController : CharacterBody3D
bool isPlayerDead = HealthSystem.IsDead();
// Handle Jumping
- if (Input.IsActionJustPressed("jump") && isOnFloorCustom()
- && !doesCapsuleHaveCrouchingHeight && !isPlayerDead)
+ if (Input.IsActionJustPressed("jump")
+ && !doesCapsuleHaveCrouchingHeight
+ && !isPlayerDead)
{
- Velocity = new Vector3(
- x: Velocity.X,
- y: Gravity.CalculateJumpForce() * (float)delta,
- z: Velocity.Z);
- }
- else if (Input.IsActionJustPressed("jump") && !isOnFloorCustom()
- && !doesCapsuleHaveCrouchingHeight && !isPlayerDead && _canDoubleJump)
- {
- _canDoubleJump = false;
- Velocity = new Vector3(
- x: Velocity.X,
- y: Gravity.CalculateJumpForce() * (float)delta * DoubleJumpSpeedFactor,
- z: Velocity.Z);
+ if (mantleLocationResult.IsOk(out var mantleLocation))
+ {
+ Position = mantleLocation;
+ }
+ else if (isOnFloorCustom())
+ {
+ Velocity = new Vector3(
+ x: Velocity.X,
+ y: Gravity.CalculateJumpForce() * (float)delta,
+ z: Velocity.Z);
+ }
+ else if (!isOnFloorCustom()
+ && _canDoubleJump)
+ {
+ _canDoubleJump = false;
+ Velocity = new Vector3(
+ x: Velocity.X,
+ y: Gravity.CalculateJumpForce() * (float)delta * DoubleJumpSpeedFactor,
+ z: Velocity.Z);
+ }
}
+
bool isHeadTouchingCeiling = IsHeadTouchingCeiling();
bool doesCapsuleHaveDefaultHeight = CapsuleCollider.IsDefaultHeight();