Skip to main content
gamedev.net
🔒 Locked

3D Vector Movement

Started by Azmeos 3 replies 600+ views
Original Post
Azmeos
Azmeos
I know this sounds simple, but I can''t figure out how to move a spaceship along a vector at a set speed. I know how to calculate the vector magnitude, but if the speed is say, 50, how do I calculate the per-second components of x, y, and z at that speed?
johnb
johnb
Say your vector is {x, y, z}, and the speed you want is s.

Work out the vector magnitude, m.

Scale x, y and z by (s/m) to give a new vector, with components

{x *s/m, y * s/m, z * s/m}.

This is the vector, with the ''per-second components'' you want. It will also work for the per frame speed: just use the correct s (e.g. a speed of 50 units per second and 30 fps gives s = 50/30 units per frame).
John BlackburneProgrammer, The Pitbull Syndicate
Azmeos
Azmeos
Thanks. So what do I do with each of those numbers? Add them to the original coordinates? Or what?
Atheist
Atheist
Position(t) = Position(t=0) + velocity * t (assuming your velocity is constant).

EDIT: Oh, and if you have a speed and a direction to move, then scale your direction (given you have it as a vector) to the speed (50 in your example) and you have the velocity.

[edited by - Atheist on August 13, 2003 1:27:43 AM]
Azmeos
Azmeos
And this velocity is one of the values in the new vector that johnb described?

Topic Locked

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

Sign in to reply to this topic.