Jump to content
  • Advertisement
Sign in to follow this  

HELP!! Angle Between 2 Character

This topic is 3873 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, Needed help here!!! How can i find a angle between 2 character in a 3d plane so that 1 of the character will always face the 1 moving around him??.. Here is the formula i've tried, i'm not sure if it is because of the moving character's x and z axis is negative. btw: i'm using dot product float ax = 10; //vector 1 float az = 0; //vector 2
  • 104
  • Your algorithm probably fails in case the angle is greater than 90°.
    Use float angle = atan2(bz, bx) to get a 4 quadrants angle.

    To convert into degrees you don't have to multiply by 2 (my advice is to use radians and never convert to degrees):
    float roty2 = angle * 180/pi; //Final Angle in Degree

    If (ax, az) is constant (10, 0) (why not (1, 0)?), roty2 is not the angle between the facing of player and AI, but the absolute orientation player must have to face AI.
    You have to update player_orientation = roty2, not player_orientation += roty2 (just to be sure ;).

    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!