# Community

O
Juan Ortega

#### Slight movement on slope when landing from a jump

Hi Nathan, The code for moving on a slope is working fine for me, however, I'm noticing a slight sliding movement down the slope whenever you land from a long jump. I've tried to fiddle with some of the code but I'm not able to fix it. Any ideas of what might be causing this?
• Nathan Lovato replied
Solution

It's due to the number of slide operations applied by move_and_slide*. By default upon colliding with a surface, the function will try to re-apply the remaining velocity of the body up to 4 times, to make you smoothly move along slopes or curved surfaces. When landing on a slope though, it causes you to move a bit.

You can update your call to move_and_slide_with_snap like so:

move_and_slide_with_snap(_velocity, snap, FLOOR_NORMAL, true, 3 if is_on_floor() else 1, PI/3)

The fifth argument is the number of slides (move, collide, and project the velocity along the surface) to apply. 3 on the floor, and 1 in the air. With these values, upon landing, the character will stop.

The 6th argument is the max angle of the slope.

• O
Juan Ortega replied

Ah, makes sense! Thank you for the explanation, it's very helpful :)

• D
Yok-Him Devn replied

Hello Nathan,

Thought I would post it here since it's related to the OP's topic.

I found that when I use

3 if is_on_floor() else 1

and jump towards the wall while keeping the direction keys pressed down my character clings to the wall and very slowly slides down.

But when I changed it back to 4, it's good again, but then the slight movement is back. Any thoughts?

• Nathan Lovato replied

It makes sense, I hadn't tested walls. The code should take walls into account and have more slides there:

3 if is_on_floor() or is_on_wall() else 1

• D
Yok-Him Devn replied

Thanks, Nathan, it works!

• Nathan Lovato replied