# mesh face player problem

## 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.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628367
• Total Posts
2982279

• 10
• 9
• 13
• 24
• 11