All Questions


Joe Sicheneder
posted to: Double jump

super high jump?

Hi, I have a problem where if you time the jump and sprint buttons correctly, you get a super high jump - somewhere around 3x or 4x the normal height of a jump.

  • Nathan Lovato replied

    Could you either wrap the code in a code block or share the files with me? It's too hard to read and spot the issue like that.

  • S
    Joe Sicheneder replied

    Sorry about that.


    func unhandled_input(event: InputEvent) -> void:
        if owner.is_on_floor() and Input.is_action_just_pressed("jump"):
            _state_machine.transition_to("Move/Air", { impulse = jump_impulse })
        if doubleJumped == false and Input.is_action_just_pressed("jump"):
            doubleJumped = true
            velocity.y = 0
            _state_machine.transition_to("Move/Air", { impulse = jump_impulse })
    func physics_process(delta: float) -> void:
        var velocityX = calculate_velocity(velocity.x, max_speed.x, acceleration.x, delta, get_move_direction().x)
        var velocityY = calculate_velocity(velocity.y, max_speed.y, acceleration.y, delta, get_move_direction().y)
        velocity = Vector2(velocityX, velocityY)
        velocity = owner.move_and_slide(velocity, owner.FLOOR_NORMAL)
        Events.emit_signal("player_moved", owner)


    func physics_process(delta: float) -> void:
        var move: = get_parent()
        if not owner.is_on_floor():
            if move.get_move_direction().x == 0:
            elif Input.is_action_pressed("sprint"):
                move.max_speed.x = move.sprintSpeed
            elif Input.is_action_just_released("sprint"):
                move.max_speed.x = move.max_speed_default.x


    func physics_process(delta: float) -> void:
        var direction = move.get_move_direction()
        if owner.is_on_floor():
            var target_state = "Move/Deceleration" if move.get_move_direction().x == 0.0 else "Move/Run"
            move.max_speed.x = move.max_speed_default.x
        if direction.x == 0.0:
            move.velocity.x = move_toward(move.velocity.x, 0, move.deceleration/5)
    func enter(msg: Dictionary = {}) -> void:
        if Input.is_action_pressed("sprint"):
            move.max_speed.x = move.sprintSpeed
        if "impulse" in msg:
            move.doubleJumped = true
            move.velocity.y += calculate_jump_velocity(msg.impulse)
    func exit() -> void:
        move.doubleJumped = false

  • Nathan Lovato replied

    Here are some things that need to change to me:

    • The double jump logic should be in Air, not in Move
    • You set doubleJumped to true on the first jump in, didn't you intend to do that only on the second jump?
    • In Move, you split the base velocity calculation into two calls for the X and Y vector components. I can't think of a case where that would be necessary or beneficial over working with the entire vector straight.

    Then, I'm not sure what causes that super high jump right now. There are some issues with the code structure, and your vertical max speed should limit the velocity's Y component. And I also can't see why it would happen just when sprinting as sprinting only affects the moveSpeed's X component.

    If you want, I can take a look at your project directly. I think the issue lies in code you haven't posted here, and it's also looking difficult to debug without reproducing the bug first in this case.