All Questions

Community

b
yousef bohadi
posted to: Double jump

partly answered

I was able to work out the logic behind having a midair jump, in the move.gd script, the following was added:

- Added at the top --> export var max_jumps: = 2.0

- Added under the func unhandled_input --> var current_number_of_jumps = 0

- Adjusted the if statements in the func unhandled_input as follows -->

if owner.is_on_floor(): max_jumps = jump_limit current_number_of_jumps = max_jumps if owner.is_on_floor() and event.is_action_pressed("Jump"): current_number_of_jumps = max_jumps - 1.0 max_jumps = current_number_of_jumps _state_machine.transition_to("Move/Air", {impulse = jump_impules}) if current_number_of_jumps < max_jumps and not owner.is_on_floor() and event.is_action_pressed("Jump"): current_number_of_jumps = max_jumps - 1.0 max_jumps = current_number_of_jumps _state_machine.transition_to("Move/Air", {impulse = jump_impules}) if current_number_of_jumps == 0 and not owner.is_on_floor() and event.is_action_pressed("Jump"): return

-----

As you might guess from the code, the second jump is not equal to the first; it can be almost double the amount if pressed immediately after the initial jump, or it can be early noticed if pressed later... One other thing I was able to add was the exported max_jumps var to the debug window. So it was nice to see the number of jumps decrease and as the character jumps in the stage

  • Correct

    Could you use code blocks when sharing code? Otherwise entire blocks get folded to one line, making them hard to read.

    If the second jump isn't equal to the first, it's due to how the jump_impulse gets applied upon entering the state: it just gets added to the current velocity.

    You need to either clamp it, or limit the jump impulse based on the current velocity when doing another jump. And that should do it. Good job!