Issue with slope physics

4.2.1

Hello, I have a small issue with my game. I’m making a 2d platformer, and i want the slopes to work a certain way. When you’re moving down a slope and transition onto a flat surface, i want the player to keep all the built-up horizontal momentum. But in my case, the player just stops dead.
Does anyone know how to fix it? The horizontal velocity also gets reset when the flat surface is farther below the ending of the slope

Hi, what is your code for movement?

direction = Input.get_axis(“ui_left”, “ui_right”)
if direction:
velocity.x = move_toward(velocity.x, direction * SPEED, 25)
lastDirection = direction
else:
velocity.x = move_toward(velocity.x, 0, 25)
move_and_slide()
I just used the template and lowered the friction a bit

Alright i figured it out, the issue is that sliding down a slope does not increase your “velocity.x”, which is what i use. Still, how do I fix that?

The reason that happens is because move_and_slide() alters the velocity to slide along the slope with projection, instead of rotation. If you use move_and_collide(), you will get more control over what happens. Also see this page.

I’ve already done quite a lot more code using move_and_slide(). Is there a way to go around this problem somehow?