Original Post
🔒 Locked
vector movement
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]
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]
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.
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]
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]
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,
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]
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]
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement