Implementing jump buffering using unity's new input system

Hello, i’ve got a functional 2D movement system and i’ve been looking at improving the feel of the controls. I’ve wanted to add jump buffering, but I am unaware of how to implement it in unity’s new input system since i’m using invoke unity events, which somewhat negates most of the tutourials out there explaining the topic as they use the old input system.

I’ve considered making the groundcheck bigger so it can detect the floor earlier but is there a better way of going about making a jump buffer? While it should work in theory I dont think it’ll look proper and it won’t work in certain scenarios…

(to elaborate, jump buffering is allowing the player to jump even if groundcheck is false, but only within a short timeframe.)

The same way you would with any other system.

You have a FixedUpdate method that continuously runs ground checks. Instead of nesting the jump input check in the “is grounded” case, have a field that represents how long it has been since the last grounded frame:

private const float CoyoteTime = 0.3f;
// Initialize like this so players cannot jump in the first 0.3 seconds if spawning above ground
private float lastGroundedTime = -CoyoteTime;
private void FixedUpdate()
{
    if (IsGrounded())
    {
        lastGroundedTime = Time.time;
    }

Now you either check for jump inputs in FixedUpdate or in an extra Jump() method, but either way, you check whether the time we were last grounded isn’t too long ago:

if (Time.time - lastGroundedTime <= CoyoteTime)
{
    // Do actual jumping
}

In a very similar way, if you are currently not grounded, you can save the time in which you pressed the Jump button. And if the button hasn’t been released and a threshold hasn’t been passed, you can trigger a jump as soon as you are grounded again.