MoveTowardsPoint2D

From XPUB & Lens-Based wiki
Revision as of 13:56, 18 October 2011 by Jasper van Loenen (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Just the formula for now, no code examples (yet)

x1, y1 = position of object to move
x2, y2 = position to move to


direction = atan2(y2-y1, x2 - x1)*180/PI;

x1 += cos(direction*PI/180)*movingSpeed;
y1 += sin(direction*PI/180)*movingSpeed;