Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

+AA_970+

rotation based on mouse coordinates

This topic is 6935 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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+

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!