Sign in to follow this  

Make 2D Object Face Another

This topic is 3460 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

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 this post


Link to post
Share on other sites
Quote:
Original post by Uphoreum
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?
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 this post


Link to post
Share on other sites

This topic is 3460 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this