0 votes

I tried to clamp players max velocity using clamp() but it keeps returning MAXSPD value. MAXSPD is set to 5

velocity.x = clamp(velocity.x , MAX_SPD, -MAX_SPD)
velocity.z = clamp(velocity.z , MAX_SPD, -MAX_SPD)

print(velocity.x , " " ,velocity.z)

Godot version 4.0
in Engine by (26 points)

What is printed if you do not clamp the velocities?

everything works fine except player speed exceeds max_spd, if i dont use clamp just the velocity gets printed. When i use clamp both velocities are stuck at 5.

1 Answer

0 votes

The second argument should be the min value, and the third argument should be the max value.

Try:

velocity.x = clamp(velocity.x , -MAX_SPD, MAX_SPD)
velocity.z = clamp(velocity.z , -MAX_SPD, MAX_SPD)
by (1,122 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.