# Rotating to a target

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

## 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 on other sites
The dot product of the heading vectors of your two objects is the cosine of the angle between them.

##### Share on other sites
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.

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632993
• Total Posts
3009760
• ### Who's Online (See full list)

There are no registered users currently online

×