Archived

This topic is now archived and is closed to further replies.

Facing a target

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

Recommended Posts

I realize this has been asked before, but looking back through so many pages I could not find a solution that actually worked, and search is basically broken. Basically I need to orientate an object to face a point. I use 3D points but all I need is the Yaw really. I''ve used a variety of methods found in posts here, but basically, I get a vector that is (point-currentposition), and from there, I''ve done any number of different things, the last thing was to use atan2(x, z) more or less, and convert it to degrees, which is one of the things I found in a post. It obviously doesn''t work, so I''m looking for a relatively simple way of just getting a yaw/heading rotation with two points. Thanks in advance.

Share on other sites
The atan2(z,x) method should have worked if all you''re looking for is yaw. Like you said:

vecToPoint = point - currentPosition;requiredYaw = radToDeg(atan2(vecToPoint.z, vecToPoint.x));

If you''re using right handed systems, the requiredYaw above will be a counter-clockwise rotation around the Y axis, where yaw=0 will fall along the z axis.

Share on other sites
Nevermind, I found the problem. My camera ends up storing the Z oddly, and as a result I had to flip the sign on the starting position, and now it faces right at the camera no matter where it goes.

Thanks for the help!

[edited by - Cor on January 23, 2004 4:28:04 AM]

1. 1
Rutin
25
2. 2
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 14
• 11
• 11
• 9
• Forum Statistics

• Total Topics
631757
• Total Posts
3002131
×