Jump to content
  • Advertisement
Sign in to follow this  
of_ownage

mesh face player problem

This topic is 3655 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 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
Advertisement
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
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!