Advertisement

Rotate to face an object, help !

Started by August 30, 2001 12:37 PM
1 comment, last by sashnil 23 years, 5 months ago
Hi all, Here''s a description of what i''m trying to acheive; i have a cannon turret and i''d like it to rotate and aim at a target. Soo i normalize my target''s vector (coords), x = 1/targetX y = 1/targetY and i use arctan(y/x) (or arctan2(y,x))to get my angles. then i convert rads to degs to verify the results. now for some reason it dosen''t return the correct angles. Is this the way to do it or am i missing something ? Any help would be much appreciated, Thanks Sash.

I don''t know if this will help, but I
got this from the documentation concerning

arctan2( y,x );

quote:

atan2 returns a value in the range –ð to ð radians,
using the signs of both parameters to determine the
quadrant of the return value.



If this is true, then the angle in degrees would be
from -180 degrees to 180 degrees. Hence it uses negative
values which could mess things up if you are trying to
get positive rotations only.

So you might try adding PI to the returned radian
measure to get only positive radian values. That will
give you a range from 0 to 2PI radians.

Hope this helps, GUY

Adulthood is the vehicle for making you childhood dreams come true.
Advertisement
Thanks Guy,

Worked perfectly !

Sash

This topic is closed to new replies.

Advertisement