# mesh face player problem

This topic is 3739 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 a problem. I want my meshes face the player. So what i do is:: 1) compute look vector from mesh 2) computer player_pos - mesh_pos = vector from player to mesh 3) compute dot product between two vectors 4) dec/inc the y rotation of the mesh and compute everything again until the dot product is like lets say <= 5 degrees. so the problem is, lets say the angle between the two vectors is 20 degress, how do i know if i should increase or decrease y rotation?? Both get the same result but if i decrease the y-rotation, i have to dec 20 degrees, else i have to start adding from 20 up until i reach the end, which makes nearly a full rotation. Any ideas? thank yo :D

##### Share on other sites
Quote:
 Any ideas?
Compute the signed angle, rather than the unsigned angle.

Assuming this is essentially a 2-d problem, you can compute the signed angle as follows:
vector3 diff = target - position;float angle = atan2(diff.y, diff.x); // Or whichever elements correspond to the ground plane
The problem can be solved in other ways as well (some of which don't require the use of angles at all). If you need more info, perhaps you could post back with more details about what you're trying to do.

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

• 9
• 9
• 14
• 12
• 10
• ### Forum Statistics

• Total Topics
633271
• Total Posts
3011161
• ### Who's Online (See full list)

There are no registered users currently online

×