How to snap a walking character to the floor?

Godot Version

4.4.1

Question

How do you get a physics based character to snap to the ground when it’s moving fairly slowly (eg, walking or running speed)? I’m working with a 2D character right now and for now am just using the default template code that Godot autogenerates for it.

I’ve created a landscape of smooth hills, and when I press left and right the character moves across it. However, it appears to be moving across it like a sled with a rocket on it, and it will have hang time even if going over a gentle hill at a moderate speed. For walking speeds, I’d like the character to snap to the ground rather than be suspended in air until gravity catches up. I think Godot used to have a move_and_slide_with_snap method, but that seems to have been removed.

I’ve had this trouble too with 3D characters walking down staircases. When they reach the end of a step, instead of stepping down they start falling until they collide with the next step.

What a good way to make characters snap to the ground for more realistic walking and running?

There is a “snap length” variable on CharacterBodies, for 2D the default value is often very low and should be elongated.

1 Like