Moving on Slopes with KinematicBody at consistent speed?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By creativeape

I’m creating a 3D third-person game and I’m using a KinematicBody with a CapsuleCollider.

I’ve got some basic movement going, with gravity and so on, but when I try moving up slopes in my terrain, movement is extremely slow and similarly, when I walk down slopes, movement is way too fast.

Is there a simple way to fix this other than doing a bunch of complex RayCasting, querying the slope collisions etc?

Thanks in advance!

:bust_in_silhouette: Reply From: creativeape

So, I’ve implemented the solution I mentioned and behold - it works fine!

  1. Add a RayCast as a child of your KinematicBody and have it collide with your walkable environment/terrain.

  2. Each frame, move it forwards relative to the wanted movement direction.

  3. check for a collision down towards the terrain and get the collision point.

  4. If the collision_point.y > kinematicbody.translation.y, apply vertical movement to our velocity.

Thanks me!- you got this! xD