Archived

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

Cor

Facing a target

Recommended Posts

Cor    122
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 this post


Link to post
Share on other sites
FReY    424
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 this post


Link to post
Share on other sites
Cor    122
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]

Share this post


Link to post
Share on other sites