Skip to main content
GameDev.net gamedev.net
🔒 Locked

Cap a Velocity

Started by Halsafar Oct 17, 2005 at 10:13 AM 1 replies 500+ views
Original Post
Halsafar
Halsafar
Okay how can I cap a velocity? I know the velocity and I know the angle travelled. I can take the magnitude to determine if the length of the velocity vector is to high but from that point I'm not sure how to cap it without corrupting the vectors direction.
timmay314
timmay314
pseudocode:

if(|v| > maxvel)   v *= maxvel / |v|


Of course you shouldn't take the square root until it is necessary to do so, so have the |v| and maxvel squared in the if statement, then take the square root if it's true.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.