0 votes

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?

in Engine by (19 points)

1 Answer

0 votes

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

by (178 points)

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 moveandslidewithsnap. How could I do that?

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

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.