MoveTowardsPoint2D: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
===== Just the formula for now, no code examples (yet) ===== | ===== Just the formula for now, no code examples (yet) ===== | ||
object | x<sub>1</sub>, y<sub>1</sub> = position of object to move<br /> | ||
x<sub>2</sub>, y<sub>2</sub> = position to move to<br /> | |||
direction = atan2(y<sub>2</sub>-y<sub>1</sub>, x<sub>2</sub> - x<sub>1</sub>)*180/PI; | |||
x<sub>1</sub> += cos(direction*PI/180)*movingSpeed;<br /> | |||
y<sub>1</sub> += sin(direction*PI/180)*movingSpeed; |
Latest revision as of 12:56, 18 October 2011
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;