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