+1 vote

Hi, I'm trying to throw together a first person character controller with a KinematicBody and I'm having trouble keeping it from sliding down slopes.

At the moment, I am using a setup like self.velocity = self.move_and_slide(velocity), and as expected the character slowly slides down any slope its put on when gravity. However, the sliding persists even when I have the stop_on_slope parameter set, and the character is on a slope that's shallow enough to be considered a floor.

Correct me if I'm wrong, but I assume this is due to the fact that the function is still returning the collision's resultant velocity, which would push the character sideways a small bit due to gravity pushing the character into the slope.

How would I go about preventing move_and_slide from pushing the character sideways when gravity is effecting them on a shallow slope? Would it be easier to use move_and_slide_with_snap instead?

Godot version 3.3
in Engine by (13 points)

1 Answer

–1 vote

move_and_slide_with_snap ( Vector2 linearvelocity, Vector2 snap, Vector2 updirection=Vector2( 0, 0 ), bool stoponslope=false, int maxslides=4, float floormaxangle=0.785398, bool infiniteinertia=true )

moveandslidewithsnap Moves the body while keeping it attached to slopes. Similar to moveandslide.

As long as the snap vector is in contact with the ground, the body will remain attached to the surface. This means you must disable snap in order to jump, for example. You can do this by setting snap to (0, 0) or by using moveandslide instead.

by (594 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.