Skip to content

Commit

Permalink
Add jump input buffering
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianGlawogger committed Jan 23, 2025
1 parent a5b2f75 commit 61b99c2
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ public class ModeFirstPersonInputHandler : MonoBehaviour
ModeFirstPerson m_PlayerCharacterController;
bool m_FireInputWasHeld;

/// <summary>
/// The last time the jump input was pressed
/// </summary>
private float lastTimeJumpPressed = float.MinValue;
/// <summary>
/// The time for how early you can press Jump in the air and still jump when touching the ground. In seconds
/// </summary>
private float jumpInputBufferingTime = 0.15f;

private void Start()
{
m_PlayerCharacterController = GetComponent<ModeFirstPerson>();
Expand All @@ -31,6 +40,19 @@ private void LateUpdate()
m_FireInputWasHeld = GetFireInputHeld();
}

private void Update()
{
if (!CanProcessInput())
{
return;
}

if (Input.GetButtonDown("Jump"))
{
lastTimeJumpPressed = Time.time;
}
}

public bool CanProcessInput()
{
return true; // TODO
Expand Down Expand Up @@ -66,7 +88,7 @@ public bool GetJumpInputDown()
{
if (CanProcessInput())
{
return Input.GetButtonDown("Jump");
return (lastTimeJumpPressed + jumpInputBufferingTime) > Time.time;
}

return false;
Expand Down

0 comments on commit 61b99c2

Please sign in to comment.