Jump is Stuttering!

Hey, I was trying to make my first 2D game. But my Jump is stuttering very strangely.
I tried to look for solution on the Internet but i haven’t found anything.
Can someone help me?
My player is teleporting to the highest point and then drops.

Greetings
1Laonnnnso

Well, could you show the code you have? There are so many things that could cause this, seeing the code would be very insightful.

2 Likes

Sure, here is the code of my Player:

extends CharacterBody2D

@export var gravity : int = 3000
@export var speed : int = 120
@export var jump_velocity : int = 2000

func _physics_process(delta):

var direction = Input.get_axis("move_left", "move_right")

if direction:
	velocity.x = direction * speed
else:
	velocity.x = 0

#Gravity
if not is_on_floor():
	velocity.y = gravity * delta
else:
	velocity.y = 0

#jump
if Input.is_action_pressed("jump") and is_on_floor():
	Jump(delta)



move_and_slide()

func Jump(delta):
velocity.y -= jump_velocity

This is more so a teleport mechanic. You change the velocity in an instant. Basically: the position changes in one single frame and changes again.

I don’t really see a way to change this, but maybe you could change the gravity and velocity values to make it less stiff.

Another issue might be that your gravity is of a higher value than your jump y_velocity.

Could you maybe please post a short video? Would help me to look for more problems

1 Like

Gravity should be added to velocity.y: velocity.y += gravity * delta
I think you’ll have to lower the jump_velocity, maybe gravity too, but you’ll see if you test it this way.

3 Likes

Thank you! This was the solution. Thanks for your help!

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.