Public Group

# Make 2D Object Face Another

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

## Recommended Posts

This probably gets asked a lot, but I couldn't find the answer for a 2D situation. I have a 2D object and I want it to face another object. They can both fully rotate 360 degrees. I'm guessing this involves some trig and I'm not particularly good at that. Could someone explain how this is done?

##### Share on other sites
Quote:
 Original post by UphoreumThis probably gets asked a lot, but I couldn't find the answer for a 2D situation.I have a 2D object and I want it to face another object. They can both fully rotate 360 degrees.I'm guessing this involves some trig and I'm not particularly good at that. Could someone explain how this is done?
If you want the object's orientation to 'snap' to the target, you can just use 'atan2':
vector2 diff = target - position;float angle = atan2(diff.y, diff.x);
If you want the object to turn toward the target gradually, it's a little more complicated (but not much). Anyway, post back if you need more details.

##### Share on other sites
Yep, that works! Well, I had to convert it to degrees first but after that it worked. Thanks so much!

I think I can take care of the gradual rotation part.

1. 1
Rutin
27
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633311
• Total Posts
3011312
• ### Who's Online (See full list)

There are no registered users currently online

×