Skip to main content
gamedev.net
🔒 Locked

Vector based velocity problem

Started by Greven 6 replies 600+ views
Original Post
Greven
Greven
Have a strange problem... I''m using a simple vector for velocity in a test app I''m writing. I want to limit the velocity of the object to 5 (just an arbitrary number). This is what I''m doing:
if(vector.Length() > 5)
{
  vector.Normalize();
  vector.Scale(5);
}
 
The functions are known to work fine. Length simply calculates the magnitude of the vector, Normalize I think we all know, and scale simply multiplies each component by the factor. It is limiting the velocity fine, but what I am finding is that as I move it looses velocity on another axis. For example I start moving right and it limits the velocity fine. But then I press up to go up, and it looses the right velocity very quickly. I know that my movement code is working ok because if I take the limiting part out, it works like a charm. What is happening to my velocities? Are they being lost in rounding? Always remember, you''''re unique. Just like everyone else.
Always remember, you''re unique. Just like everyone else.Greven
Palidine
Palidine
what variable type are your vector components?

-me

[edited by - Palidine on April 9, 2002 7:37:59 PM]
Greven
Greven
They are floats

EDIT: Just tried double in case your wondering and it did the same thing...

Always remember, you''re unique. Just like everyone else.

[edited by - Greven on April 9, 2002 7:43:00 PM]
Always remember, you''re unique. Just like everyone else.Greven
Palidine
Palidine
i think i got it.

step through what happens

you are basically saying that the OVERALL magnitude of the velocity never goes above 5. which means that say your rightness was close to 5 (primarily going right). now you are start going up, but the total magnitude of the velocity still needs to be no bigger than 5. the only way to keep the magnitude the same is to decrease the speed that you are traveling right.

with each iteration if you increase the upness you also decrease the rightness.

your magnitude is:

sqt(v.x * v.x + v.y * v.y + v.z * v.z) = magnitude

the only way to keep the same magnitude is to decrease the y and z if you increase the x

got it?

-me

[edited by - Palidine on April 9, 2002 7:48:43 PM]
Greven
Greven
*blushes*
just noticed that...
I just did a check on each axis to make sure they never got above 5 and it works like a charm now. Have to remember to keep the axis separate...
thnx

Always remember, you''''re unique. Just like everyone else.
Always remember, you''re unique. Just like everyone else.Greven
Palidine
Palidine
np,

got me thinking though. in FPSes like unreal tournament do they do intentionally what you mistakenly did?

it kinda makes sense that you can only run at a certain speed, right? so if you are moving forward and strafing at the same time you would want to limit the resultant velocity. if you didn''t limit it, it would be bigger than either running or strafing so you should run + strafe at the same time always...

it''d be easy to test. just get in multiplayer and have someone run past you. then strafe + run past you and see if they are faster or slower.

interesting....never would have thought about that w/out your post.

so thank you...

-me
Praestat
Praestat
Palidine, I had that same thought (about FPS''s) when I read the solution to this problem. EverQuest might be a candidate for a game that did not limit the resultant velocity: When running+strafing, you could outrun NPC creatures that should be able to run at the same speed as you. (I have no way of proving this though, since it could''ve also been due to EQ''s notoriously poor AI pathfinding. Also, since I haven''t played the game in about a year, I can''t verify that it is still this way.)

Topic Locked

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

Sign in to reply to this topic.