Open creativitRy opened 7 years ago
1 brings the issue where the jump sensor is abused to do stuff like wall jumping. Check time since last grounded and precalculate future
2 can account for late jump presses. When user doesn't jump and grounded turns false, start the timer. While timer is active, user can jump (which registers as jump on ground)
There are a few issues on making a more fluid jump input
Here are a few ways I can fix this.
1 - Multiple Sensors
Have two sensors on the bottom of the player: One (D) for detecting whether the player is on the ground, and one (J) to allow jumping. J will overlap D and will be slightly larger. It will compensate for early/late taps of the jump button. Issue 2 can be resolved by having a jump cooldown time (like 0.25 seconds or so).
2 - Float Field
Have a float. If it is positive, then it indicates that user wants to jump. If it is 0, then the user cannot jump. When the player presses the jump button, the float is assigned 1. Then it decrease by dt every frame until it reaches 0. If the player is grounded while the float is positive, then the player jumps and the time resets to 0. Issue 2 can be resolved by having a jump cooldown time.
Pros and Cons
1 can account for late jump presses. 2 can't. 2 is less cpu intensive 1 might have this potential issue where the player presses the jump button so early that it is registered within the cooldown time. I don't see any way of how this can be a problem