ld-gd: basic greyboxing, double jump

This commit is contained in:
2025-05-21 19:36:40 +02:00
parent b3a28436bc
commit 67461aa4be
4 changed files with 128 additions and 18 deletions

View File

@ -29,7 +29,9 @@ public partial class FieldOfView: Node3D
public void PerformFovAdjustment(FovParameters parameters)
{
float velocityClamped = Mathf.Clamp(
parameters.Velocity.Length(), 0.5f, parameters.SprintSpeed * 2.0f);
Mathf.Abs(parameters.Velocity.X) + Mathf.Abs(parameters.Velocity.Z),
0.5f,
parameters.SprintSpeed * 2.0f);
float targetFov = BaseFov + FovChangeFactor * velocityClamped;

View File

@ -24,6 +24,11 @@ public partial class PlayerController : CharacterBody3D
[Export(PropertyHint.Range, "0,100,0.1,or_greater")]
public float CrouchTransitionSpeed { get; set; } = 20.0f;
[Export(PropertyHint.Range, "0,5,0.1,or_greater")]
public float DoubleJumpSpeedFactor { get; set; } = 2f;
private bool _canDoubleJump = true;
private float _currentSpeed;
private const float DecelerationSpeedFactorFloor = 15.0f;
@ -115,6 +120,7 @@ public partial class PlayerController : CharacterBody3D
if (isOnFloorCustom())
{
_lastFrameWasOnFloor = Engine.GetPhysicsFrames();
_canDoubleJump = true;
}
// Adding the gravity
@ -139,6 +145,15 @@ public partial class PlayerController : CharacterBody3D
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);
}
bool isHeadTouchingCeiling = IsHeadTouchingCeiling();
bool doesCapsuleHaveDefaultHeight = CapsuleCollider.IsDefaultHeight();