Jump to content
  • Advertisement

Archived

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

ligh

vector movement

This topic is 5823 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

lets say i have a struct that has a 2d position vector and a 2d velocity vector, to project it to the screen, i would use the x, y coords from the position vector (right?), then how would i go about calculating it''s next position such that it only moves 1 pixel per frame? thanks

Share this post


Link to post
Share on other sites
Advertisement
If that is the case you take your 2d velocity vector, make it a unit vector (so it only moves your position vector 1 pixel/unit at a time) and add it to your position vector.
So:
V(velocity vector)=(x,y)
|U|(unit velocity vector)=|V|/a=1
a- some scalar

P(position vector)=(x1,y1)
P(new position)=P+U


EPHERE

[edited by - EPHERE on December 5, 2002 12:36:05 PM]

Share this post


Link to post
Share on other sites
Your velocity vector should have a magnitude of one. The magnitude is its length and given by sqrt(x*x+y*y). To set a vector a desired length you multiply by the desird length divided by the current length. Once your velocity vector has the right length you just add it to the position. Strictly speaking for linear motion at a constant velocity it is position+velocity*time, but here your velocity is in pixels per frame and your time is measured in frames.

Share this post


Link to post
Share on other sites
ok, so if my data is,
Pos(2,3)
Vel(2,3)

my |V| is 2*2+3*3 = sqrt(13)

then i get stuck..
what next?

thanks

[edit]

ah., ok, so i would then go
U = V/|V| to give me the unit vector..?
and add U+P.. ?


[edited by - ligh on December 5, 2002 6:03:54 PM]

ah ha, would u look at that.,
thanks for all the help EPHERE and LilBudyWizer!!

[edited by - ligh on December 5, 2002 6:10:04 PM]

Share this post


Link to post
Share on other sites
Pixels are discrete units. If you direction is (1,1), normalizing it won''t make you move one pixel/frame... What do you want exactly?

Cédric

Share this post


Link to post
Share on other sites
if i have an object, with an x,y for position and x,y for velocity, it will move across the screen at the given velocity, but smooth pixel/pixel movement..

eg,

struct vector
{
float x,y
}

struct obj
{
vector pos
vector vel
}

obj p;
p.pos.x = 100;
p.pos.y = 100;
p.vel.x = 10;
p.vel.y = -1;


after a time it should end up at 110,99 but i want it to visit all the places on the line along the way

and.. if i have two objects, p1, p2 given
p1.pos.x = 100
p1.pos.y = 50
p1.vel.x = 10
p1.vel.y = 0
p2.pos.x = 100
p2.pos.y = 150
p2.vel.x = 5
p2.vel.y = 0
the p1 shoudl move faster then p2..

[edited by - ligh on December 7, 2002 3:24:59 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!