Hello! I am making an FPS game and I want to implement a Double Jump. Currently, I have it so that if the player taps the jump key, they will do one jump. If they press and hold down the jump key, they will automatically jump again as soon as they hit the ground. I want to implement a double jump with these controls in mind, similar to how Doomguy’s double jump works in Quake Champions, where he auto-hops when the jump key is held down, but can double jump if the jump key is pressed while in the air.
I know that adding additional jumps is very straight forward, but when I try to add a second jump while the press and hold to jump code is active, I will “moon jump” indefinitely by holding the jump key down.
How can I make it so that the player will only do a double jump if they press the jump key while already in the air, while pressing and holding down the jump key will do the auto-hopping? Thanks for your help!
You could just apply jump on input Release instead of Pressed.
For the automatic jump, toggle a boolean when you press the Jump Input setting it to true, and set it to false when you release or apply the jump. Then you can use the “OnLanded” event available for Characters to determine if you have to do the automatic jump based on that bool.
Here is my blueprints for the jump command. Originally, I was using the enhanced input action for the jump, and move on to a regular input action to try and go along with your suggestion. Either of these really worked. Lmk if this is wrong and should be something else.
Since I’m using the Enhanced Input Action, I can take advantage of the fact that “Triggered” and “Started” are considered different states. The “triggered” action always happens even when a button is held, allowing for the auto-jump!
The “Started” action only activates on the “press”. So once the player presses jump, I check if my max jump count is NOT equaled to 2. If it isn’t, I jump, increment the jump count, and then check if its now equal to 2 while the player is falling. Then, I reset the jump count to 1 as soon as the player hits the ground.
I set an extremely fast delay for the “Event On Landed” so that the jump actually resets, and the count will reset to 1 before the player could cause an infinite jump.
This is a similar logic that I used for my dash mechanic. Didn’t think to use that until I remembered how that worked!
Glad you could find a solution.
Btw, you have a DelayUntilNextTick node, which is better for this situations rather than doing “Delay(0.001)” if that would work for you.
Also, Triggered is called for every activation of the input, so I’m not sure that’s exactly what you want. Started is the equivalent to the old Pressed, so if what you want is to “Hold” the second jump, it would probably be best to use Completed, which is the Released equivalent.
Your current BP triggers jump on Started, Completed, Canceled and Ongoing, even if Jump does nothing. Consider that you can literally set the max amount of jumps allowed on the Character, so you wouldn’t need to check Max Jumps or anything.