MoveTowardsPoint2D: Difference between revisions

From XPUB & Lens-Based wiki
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 = thing to move, target = where to move


direction = atan2(targetY-objectY, targetX - objectX)*180/PI;
direction = atan2(targetY-objectY, targetX - objectX)*180/PI;


objectx += cos(direction*PI/180)*movingSpeed;
objectx += cos(direction*PI/180)*movingSpeed;<br />
 
objecty += sin(direction*PI/180)*movingSpeed;
objecty += sin(direction*PI/180)*movingSpeed;

Revision as of 13:11, 18 October 2011

Just the formula for now, no code examples (yet)

object = thing to move, target = where to move

direction = atan2(targetY-objectY, targetX - objectX)*180/PI;

objectx += cos(direction*PI/180)*movingSpeed;
objecty += sin(direction*PI/180)*movingSpeed;