Archived

This topic is now archived and is closed to further replies.

Dark_Streak

Basic Motion question

Recommended Posts

Hello, I have a quick question about vector calculations, I would appreciate any comments I have an object that can move around a 3D world. I am using keyboard input to drive the object forward and backwards, and to strafe it to the sides as well. I am using a 3D vector (called motionVec) to store this objects speed. MotionVec.x is the speed the object is moving left or right and motionVec.z is the speed of the object going forwards and backwards. Now, this is probably a well known problem, but I am fairly new to implementing basic physics so I am unsure how to solve my problem, and my problem is this: if I am driving the object forward, it travels forwards correctly at the speed I set. If I am driving the object in a strafing fashion (to the side), it also moves at the correct speed. However, if I press forward and strafe left on the keyboard, the object travels forward and to the left at the same time (in a diagonal direction), which is correct, but my speed is nearly doubled! So I want my object to be able to strafe and move forwards/backwards together, but I don’t want the total speed of the object to be multiplied. I imagine that my problem lies in the fact that when the object is translated by motionVec, it is moved to a resulting vector of the z and x axis. How can I avoid this problem?

Share this post


Link to post
Share on other sites
I am still in the 2D world, but hey i don''t see the problem the vectors add their scalar quantities (speed) since now they are on the same path so why don''t you just divide it by the quantity again...

like in your "if" that you have on pressing both forward and left where-ever you set the speed for that diagonal direction divide it by the quantity....

Cheers.

Share this post


Link to post
Share on other sites
Thanks guys,

So your saying that I should implement a check to see if I am travelling in more than one direction at once, IF I am then I devide the resulting vector by the square root of 2? Is this correct?


[edited by - Dark_Streak on July 8, 2003 6:41:17 AM]

Share this post


Link to post
Share on other sites
all i was saying is what you already know:

if your two vectors multiply and their diagonal speed is speedDiag, then just devide it by the default vector speed :-)

I don''t think you need to call the Greek Pythagoras in this case :-)

Share this post


Link to post
Share on other sites