Sign in to follow this  
of_ownage

mesh face player problem

Recommended Posts

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


Link to post
Share on other sites
jyk    2094
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.

Share this post


Link to post
Share on other sites

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