Skip to main content
gamedev.net
🔒 Locked

Face vector dir

Started by astrospider Jan 23, 2006 at 5:58 AM 0 replies 900+ views
Original Post
astrospider
astrospider
I have a object that I want to rotate so it face the same dir as a vector.. I can't get the rotation to work correct... I have used dot product but I think I have done something wrong :p Anyone that can help me? Thanks in advance
Zakwayda
Zakwayda
Here's the usual answer:

1. Find the angle between the forward vector a and the goal direction vector b, using
2. acos(clamp(dot(a,b)/sqrt(a.lenSqr()*b.lenSqr()),-1,1)), [I think I got that right...] or
3. atan2(length(cross(a,b)),dot(a,b)) [better, IMO]
4. Find the axis of rotation as cross(a,b)/length(cross(a,b)), making sure to...
5. Bail if length(cross(a,b)) is too small.
6. Construct a rotation matrix from this axis-angle pair.
7. Multiply it by your current rotation matrix.

Topic Locked

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

Sign in to reply to this topic.