How to Crest Hills without Flying Into Space - CharacterBody3D Terrain Movement

Godot Version

4.6.beta

Question

Hi! I have a problem that I’m sure is a common situation, but I’m not finding any posts that directly address it.

I’m making an open world that a character can run around in. I’m using Terrain3D to do so, and I’ve made many hills and valleys to traverse. I have a characterbody3D on my player, and my code for moving around works fine on flat areas, or for moving uphill. However, anytime I’m moving downhill, or crest a hillside, my character’s momentum usually has me moving forward into space, like they leap straight forward every time they move instead of having the forward direction naturally slope downward. I was hoping for a more “natural” movement, where forward movement corresponds to the slope on which the character is moving/standing.

In my research, I stumbled on the get_floor_normal() function. Code like the following was suggested:

var forward = -camera.transform.basis.z

if is_on_floor():
    forward = forward.slide(get_floor_normal()) 

forward = forward.normalized()

But it still doesn’t quite work - especially when cresting a hill, I wind up flying off into space more than moving down in a natural way.

Are there any guides or tips that people have for smoothing out “natural” motions like this? I figure this has to be an oft-addressed topic somewhere, but none of the tutorials I see seem to focus on refining movement details like that.

Try changing the CharacterBody3D.floor_snap_length to a bigger value

That did it, thank you so much!!

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