idanarye / bevy-tnua

A floating character controller for Bevy

Home Page:https://crates.io/crates/bevy-tnua

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Prevent repeated jumping when holding the jump button

idanarye opened this issue · comments

Currently, if you just keep holding the jump button, once the character lands it'd immediately jump again. This needs to be prevented (or configurable?)

The VVV video mentions a "jump buffer". This behavior made it unnecessary, but now that I'm fixing it I should add a jump buffer.

Also, I consider adding a "delayed jump holding", where holding the jump will make the character jump again X seconds after landing.

I'm thinking about something like this:

enum JumpCommandState {
    Unissued,
    Buffered(Timer),
    Consumed,
}

Unissued would be the usual state, when the user is not pressing the button. When jumping, the jump command state will change to Consumed - and from this state, jumps would be impossible.

When pressing jump in the air (or in other situations where a jump would be impossible), the jump command state (only if Unissued) would change to Buffered (with a configurable duration for the timer). If a jump becomes possible while the key is pressed and the command state is Buffered, the timer will be checked. If it is not expired, there won't be a jump.

Another option is to check the timer when updating, and if it is expired automatically move the state to Consumed.

I'm also thinking to include a Cooldown(Timer) state, which will be entered if the player holds the button, the jump is Consumed, and a jump becomes possible. Once the cooldown timer is expired, the character will jump (assuming a jump is still possible)

The cooldown duration will be configurable. A cooldown of zero will be the current behavior, and an infinite cooldown will prevent automatic jumping when the button is held.

I also consider using the same state for air actions - but they require some more design. For now I'll just call it JumpCommandState and just rename it in the future if I need to.