Finding an Angle
Hello there,
I was just wondering if someone could give me some help on a little problem that I am having to find the angle that a character in a game has to rotate to face the direction that the user has clicked.
For example:
My charcater is facing North, say his location is 0,0,0
the player clicks on the point 10,0,-10 so the character would have to rotate 135 degrees - so what would the formula be to work this out so i can return the value from -180 degrees to 180 degrees.
Thanks in advance
Sam
You can use a dot product. A_x*B_x + A_y*B_y + A_z*B_z=|A|*|B|*cos(angle)
where the _x is a component in the x direction and |A| means the magnitude of A. Solve this and use arctan to get the angle.
[edited by - grady on January 15, 2003 9:26:15 PM]
where the _x is a component in the x direction and |A| means the magnitude of A. Solve this and use arctan to get the angle.
[edited by - grady on January 15, 2003 9:26:15 PM]
----------------------------www.physicsforums.comwww.opengl.org
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement