Angle from Vector
Hey, I've been trying to work this out for a while, done some searching and am now more confused than ever.
Essentially, I am working in 2D and have a set of objects. These objects have two 2D Vectors, one storing their position, and one storing their velocity. What I would like to do is somehow create an angle that can be used to rotate the object around the Z axis so that visually, it's heading is the same direction as it's velocity (so it points where in the direction it's moving).
I have tried various combinations of atan2, dot product, etc with no result.
Can anyone help?
Quote:Original post by MrDoomThe standard solution would be:
Hey, I've been trying to work this out for a while, done some searching and am now more confused than ever.
Essentially, I am working in 2D and have a set of objects. These objects have two 2D Vectors, one storing their position, and one storing their velocity. What I would like to do is somehow create an angle that can be used to rotate the object around the Z axis so that visually, it's heading is the same direction as it's velocity (so it points where in the direction it's moving).
I have tried various combinations of atan2, dot product, etc with no result.
Can anyone help?
angle = atan2(direction.y, direction.x);
This assumes that your objects point down the positive x axis in their default orientation (recommended); if not, you have to modify the arguments to and/or the return value from atan2().Another option is to create the orientation matrix directly from the direction vector.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement