# Rotating an object to face cursor

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

## Recommended Posts

Sorry to trouble you with something so simple. I'm making a little 2d topdown game and I want the player to rotate to face the cursor. I've explored a couple ways and gotten it to work well enough, the only problem is that the player sits at 0,0 and all my methods require special consideration when the cursor either passes the x or y axis. Is there a really easy way to do this without alot of special case work?

##### Share on other sites
Take a look at this thread

http://www.gamedev.net/community/forums/topic.asp?topic_id=263747

and see if maybe it gives you some ideas. If you've got more questions (or could be a little more specific) then ask away.

##### Share on other sites
Quote:
 Original post by Bucket_Head in that other threadSo you can get the angle using a call to arcsine or arccosine (I believe it's asin and acos - those all work in radians, of course) but be a little careful of the domain and range on those suckers, you may need some ifs to determine what quadrants you're in. Once you've got the angle you could feed that to your graphics API and just rotate the whole quad.

That was the portion I was trying to avoid =) Thanks for your help.

[Edited by - wild_pointer on August 18, 2004 2:36:12 PM]

##### Share on other sites
This is what I use:
typedef struct{int xint y;}float LookAt(vec2 a, vec2 b){	vec2 diff;	diff.x = a.x - b.x;	diff.y = a.y - b.y;	return (float)atan2(diff.y,diff.x);}

1. 1
2. 2
Rutin
22
3. 3
4. 4
frob
18
5. 5

• 33
• 13
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
632566
• Total Posts
3007107

×