I recorded the issue because its hard to describe. The video can be found here.

I am desperate for help, I have been struggling with this for weeks.

The code in the video can be examined further here (the relevant player code is here).

Thank you to anyone who takes the time to help me.

in Engine
edited

Have you attempted to use moveandslidewithsnap() at all?

Of course. You can see that in the code. That is what I am currently using, not using moveandslidewithsnap makes it not slide down a bit but instead it makes the player jump after climbing a slope.

Just in case somebody else runs into this problem. The issue is that while you can set `move_and_slide` to not slide down slopes, the gravity is still used to calculate the movement against the slope's normal.

A simple fix for me was to cancel out the sideways movement caused by the gravity pushing the character against the slope. This can be calculated with the floor normal.

A simple example:

``````velocity = ....
velocity = player.move_and_slide(velocity, Vector3.UP, true)
``````

The previous snippet would result in downwards movement when moving sideways and different speeds for going up and down the slope, like this weird movement

However, if we take the floor normal and multiply it by the affecting gravity, we can cancel out the effect

``````var correction = Vector3(0,0,0)
if player.is_on_floor():
correction = Vector3(0,1,0) - player.get_floor_normal()
correction *= GRAVITY
correction *= -1
velocity = ....
velocity = player.move_and_slide(velocity + correction, Vector3.UP, true)
``````

Our player will now behave as if it was walking on a flat surface.

by (58 points)