# Rotate player to object

This topic is 3223 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

How can I go about calculating the amount that i need to rotate the player to face an object? The players view angles are given as (x,y) where x is up/down and y is left/right. I need to calculate from knowing the origin of the player (x,y,z), where its facing, and the origin of the object to face (x,y,z) how much to increase/decrease x and y. Thanks!

##### Share on other sites
Ok I'm not sure I follow your description of the players angles of (x,y). In a 2d game you would have a single YAW angle in the XY plane. When you add a third dimension PITCH comes into play.

First construct a vector from the player to the target. i.e. Diff(xyz) = Targ(xyz) - Player(xyz).

Then you can use ATan2 to calculate the YAW angle using atan2( diff.x, diff.z ). Finally calculate the pitch using asin( diff.y / magnitude(diff) )

That will give you two angles in absolute terms. If you set the players pitch and yaw to those values it should face in the direction you want.

##### Share on other sites
Minor issue, im using a scripting language, and it has no built in math functions.
Working on implementing atan2 using CORDIC... Should be fun
http://www.worldserver.com/turk/opensource/index.html#CORDIC

1. 1
Rutin
29
2. 2
3. 3
4. 4
5. 5

• 13
• 13
• 11
• 10
• 13
• ### Forum Statistics

• Total Topics
632960
• Total Posts
3009478
• ### Who's Online (See full list)

There are no registered users currently online

×