Mario-type jumping doesnt really work well

hey! so i’m using godot 4.6.3 and my code which is this

func _process(delta: float) -> void:
	velocity.y += customplayergravity
	if Input.is_key_pressed(KEY_A):
		velocity.x -= 500
	if Input.is_key_pressed(KEY_D):
		velocity.x += 500
	if Input.is_key_pressed(KEY_W) and is_on_floor():
		velocity.y = -750
	if not Input.is_key_pressed(KEY_W) and velocity.y < 0:
		velocity.y *= 0
	if velocity.y < -750:
		velocity.y = -750
	move_and_slide()
	velocity.x = 0

it feels really clunky and not like actual mario type jumping and i dont really know how to fix it D:

Have you done any research on how Mario-type jump work? That will be the first step.

Many games have custom ways of handling physics that makes the game controls unique. This is why jumps feel different from game to game.

of course i have! this does work and it is like mario type jumping but it feels extremely clunky and weird, i could give a demonstration or something

Please do.

i want it to kinda be like the normal jump and not stop instantly

What’s a “normal jump”?

the last jump? the one where it did the full jump? thats a normal jump

Set the jump upward velocity only once when the up key is pressed.

read my code:

extends CharacterBody2D
var customplayergravity = 25

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta: float) -> void:
	velocity.y += customplayergravity
	if Input.is_key_pressed(KEY_A):
		velocity.x -= 500
	if Input.is_key_pressed(KEY_D):
		velocity.x += 500
	if Input.is_key_pressed(KEY_W) and is_on_floor():
		velocity.y = -750
	if not Input.is_key_pressed(KEY_W) and velocity.y < 0:
		velocity.y *= 0
	if velocity.y < -750:
		velocity.y = -750
	move_and_slide()
	velocity.x = 0

I DO THAT!

No you don’t. You’re obstructing the normal jump behavior if the up key is not held.

ohhh i understand! but i do not like using actions and i dont think Input.is_key_just_pressed exists

Define actions for your controls in project settings and then you’d be able to use Input.is_action_just_pressed().

Doing it like you’re currently doing is also fine but get rid of the part that sets y velocity to 0 if the key is not held.

isnt that what does the mario type jump?

I have no idea. Haven’t played Mario since 1985.

Nothing looks “wonky” in the video you posted. It behaves exactly as you’d expect it to. If you want different behavior you’ll have to describe it precisely or make a visual mockup.

so, basically, in my code it sets it to zero (no matter what i do) in mario, it basically keeps the velocity but stops the jump from me going up. get it now?

OH HELL YEAH I FIXED IT WOOHOO yay