rotation based on mouse coordinates

Started by
2 comments, last by +AA_970+ 23 years, 12 months ago
Hi, in my top down 2d game i want it so that when the mouse is moved the player rotates to face the cursor. My problem is that i don''t know how to use the coordinates to determine the angle the player will face. Does anyone know how to do this or have any suggestions? +AA_970+
Advertisement
using tan, of course!
first, figure out the x disntance between the mouse and the player, and the y distance between the mouse and the player. then use the formula:

tan x = y/x

then use the special arctan function using y/x to find x, which is the angle.
Thanks alot!!!
I should probably get used to dealing with trig.

+AA_970+
please remember to use tan, and arctan look up tables to speed up the game so cpu time can be used elswhere (it'' always nice to have better AI)

I have always been lost!
Sentence you never want to here: Is it ok to eat the fuzzy stuff in your belly button?

This topic is closed to new replies.

Advertisement