Skip to main content
GameDev.net gamedev.net
🔒 Locked

Facing a target

Started by Cor Jan 22, 2004 at 10:53 PM 1 replies 450+ views
Original Post
Cor
Cor
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.
FReY
FReY
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.


do unto others... and then run like hell.
Cor
Cor
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]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.