How to move on slopes at a consistent speed with a KinematicBody2D?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By gazer500

I’m using move and slide with snap to move:

var snap_vector := Vector2(0, 64) if !is_jumping and is_grounded else Vector2.ZERO
total_velocity = move_and_slide_with_snap(velocity * delta, snap_vector, Vector2.UP, true, 4, rad2deg(max_slope))

If I’m moving up a slope, I move slower, and if I move down a slope, I move faster. Not only that, but I move faster/slower at different slope angles. I’d prefer to move at a consistent speed on slopes. I tried using the RayShape2D, but that did not change my slope speed (also, collision is weird using the RayShape2D, so I’d prefer to avoid using it). Is there any way I can make my speed consistent?

:bust_in_silhouette: Reply From: A112Studio

The fastest way would be to use clamp method on your speed variable speed=clamp(speed,min_speed,max_speed)

Clamping the speed variable itself does nothing (I also tried clamping the velocity variable’s x-value, but that doesn’t work either). However, I think it could work if I could clamp my end velocity after it’s calculated by move_and_slide_with_snap. How could I do that?

gazer500 | 2020-05-10 18:25

Maybe you don’t clamp the speed enough? You can’t clamp the ‘result’ after it’s calculated, the best option is to use clamped value in move_and_slide

A112 | 2020-05-11 08:46