gd: simple mantle
This commit is contained in:
@ -10,4 +10,7 @@
|
||||
<ItemGroup>
|
||||
<Folder Include="addons\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="RustyOptions" Version="0.10.1" />
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -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<Vector3, string> 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<Vector3, string>("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<Vector3, string>("No collision found");
|
||||
}
|
||||
}
|
||||
|
@ -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,16 +144,23 @@ public partial class PlayerController : CharacterBody3D
|
||||
bool isPlayerDead = HealthSystem.IsDead();
|
||||
|
||||
// Handle Jumping
|
||||
if (Input.IsActionJustPressed("jump") && isOnFloorCustom()
|
||||
&& !doesCapsuleHaveCrouchingHeight && !isPlayerDead)
|
||||
if (Input.IsActionJustPressed("jump")
|
||||
&& !doesCapsuleHaveCrouchingHeight
|
||||
&& !isPlayerDead)
|
||||
{
|
||||
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 (Input.IsActionJustPressed("jump") && !isOnFloorCustom()
|
||||
&& !doesCapsuleHaveCrouchingHeight && !isPlayerDead && _canDoubleJump)
|
||||
else if (!isOnFloorCustom()
|
||||
&& _canDoubleJump)
|
||||
{
|
||||
_canDoubleJump = false;
|
||||
Velocity = new Vector3(
|
||||
@ -162,6 +168,8 @@ public partial class PlayerController : CharacterBody3D
|
||||
y: Gravity.CalculateJumpForce() * (float)delta * DoubleJumpSpeedFactor,
|
||||
z: Velocity.Z);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool isHeadTouchingCeiling = IsHeadTouchingCeiling();
|
||||
bool doesCapsuleHaveDefaultHeight = CapsuleCollider.IsDefaultHeight();
|
||||
|
Reference in New Issue
Block a user