iDevGames Forums
Direction formula? - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Direction formula? (/thread-603.html)



Direction formula? - TimMcD - Nov 11, 2009 11:11 PM

I was wondering if anyone has any information on how to calculate the angle at which to rotate an object based on an x,y set of information?
Ie:
A circle has a point on it that I want to face the mouse. I have the x,y of the circle, and the x,y of the mouse. How can I figure the angle at which to rotate the circle?


Direction formula? - Skorche - Nov 11, 2009 11:22 PM

Code:
atan2(mousey - circley, mousex - circlex)
Result is in Radians. Multiply by 180/PI to convert to degres.


Direction formula? - TimMcD - Nov 11, 2009 11:42 PM

Thank you very much!