Thursday, August 7, 2025

Mega Man 9 jump in Godot

A while ago I tried to recreate the jump mechanic of Mega Man 9 in Godot. Here is what I came up with:
 
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

No comments:

Post a Comment

Object Timers in GDevelop are a way to have a timer per object. On the other hand Scene Timers are timers which execute globally for the who...