+2 votes

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.
(This uses the most recent version of Godot: 3.2.2)

in Engine by (52 points)
edited by

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.

For those still struggling with this issue. Make Gravity the last thing you calculate, I struggles with this for a long time but fixed it by simply moving the gravity calculation to the bottom. Make sure to use the is_on_floor() signal also.

if not is_on_floor():
    velocity.y -= gravity * delta

moveandslidewithsnap worked the best for me also.

Holy crap thank you for this! Weird slope behavior has been giving me fits for literally months and I had no idea how to track down what was causing all the odd stuff. Calculating gravity after everything else seems to have fixed all of it.

1 Answer

0 votes

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 (60 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.