Jump to content
  • Advertisement
Sign in to follow this  
Terrimus

Rotating to a target

This topic is 3406 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 I have tried many approaches with no luck so now I am asking here :O I got an object I want to rotate to face another object. The transformation of the objects are stored in a 4x4 matrix. I just want to rotate around the Y-axis so what I really want is the angle between the objects current rotation and the targets location?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
The dot product of the heading vectors of your two objects is the cosine of the angle between them.
@The OP: Just for completeness I'll mention that the above will give you the unsigned angle; in order to determine which direction to turn, you'll need to do a little additional math, or just compute the signed angle to begin with.

My preferred method for computing the signed angle between two vectors in 2-d (which is essentially what you're wanting to do) is the following:
angle = atan2(perp_dot(a,b), dot(a,b));
This will tell you both in what direction you need to turn, and how far.

There's a variety of other ways to orient an object towards a target, but they may or may not be applicable in this case (I don't know what you're doing exactly, so I can't say for sure one way or another). If all you need is the signed angle though, the above is the way to do it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!