MoveTowardsPoint2D: Difference between revisions

From XPUB & Lens-Based wiki
m (Created page with "===== Just the formula for now, no code examples (yet) ===== direction = atan2(targetY-objectY, targetX - objectX)*180/PI; objectx += cos(direction*PI/180)*movingSpeed; objecty...")
 
No edit summary
Line 2: Line 2:


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;
objecty += sin(direction*PI/180)*movingSpeed;
objecty += sin(direction*PI/180)*movingSpeed;

Revision as of 12:10, 18 October 2011

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

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

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

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