Dienstag, 12. September 2023

Mega Man 9 Jump

export (int) var jump_speed = -400
export (int) var gravity = 1200

var jumping = false

func _physics_process(delta):
    if Input.is_action_just_pressed('jump') and is_on_floor():
        jumping = true
        velocity.y = jump_speed

    if jumping and Input.is_action_just_released("jump"):
        if velocity.y < -50:
        velocity.y = -50

    velocity.y += gravity * delta

    velocity = move_and_slide(velocity, Vector2.UP)

    if jumping and is_on_floor():
        jumping = false

Source: https://ask.godotengine.org/26160/jump-godot-holding-button-higher-jump-tapping-100%25-same-height?show=74579#a74579