My speed variable isn't updating when landing

Godot Version



I am making a replication of Sonic physics, and I’ve been running into a problem when landing on a slope. Here’s the code I have for it currently:
The idea is that I want to convert the air velocity to gSpeed (Ground Speed) when landing. My problem is that the gSpeed variable doesn’t seem to update when the code is ran, it just resets when the player lands. I’ve tried moving when the code is executed, but that doesn’t seem to have any effect. Is there a problem I’m not seeing?

how is this function called? Could you paste your script?

type or paste code here

Of course!

	if grounded:
		if landed:
			landed = false
		justJumped = false
		velocity.x = gSpeed * cos(deg_to_rad(angle))
		velocity.y = gSpeed * -sin(deg_to_rad(angle))
		if !landed:
			landed = true

I did it like this so that it only ran the moment the player lands on the ground. I also run it through the move and slide function afterwards.

1 Like

You might need to store the last velocity. move_and_slide will have already ate up your velocity by this point. Maybe more useful to to use move_and_collide and resolve collisions manually, if the “slide” part isn’t doing you well.

1 Like