Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

2D VECTOR TRAVEL

Name: Anonymous 2011-05-21 14:17

Simple problem but i just cant find a nice sollution.

I have a two 2d points, the object starts at point 1 and travels to point 2 at some speed.

Also if it gets somewhat easier i also have the angle at which the object needs to travel.

Anyone can write something fast?

Name: Anonymous 2011-05-21 14:26

points are described by (x1, y1) and (x2, y2)
speed of travel is speed


xdist = x1 - x2
xdir = xdist / abs(xdist)
ydist = y1 - y2
ydir = ydist / abs(ydist)
totaldist = sqrt(xdist * xdist + ydist * ydist)
xfrac = xdist / totaldist
yfrac = ydist / totaldist
xspeed = xfrac * speed * xdir
yspeed = yfrac * speed * ydir


And then, at every timestep, add xspeed and yspeed to current x and y coordinates.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List