Archived

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

Azmeos

3D Vector Movement

Recommended Posts

Azmeos    122
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?

Share this post


Link to post
Share on other sites
johnb    351
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).

Share this post


Link to post
Share on other sites
Atheist    150
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]

Share this post


Link to post
Share on other sites