# Angle from Vector

This topic is 3907 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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?

##### Share on other sites
Quote:
 Original post by MrDoomHey, 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?
The standard solution would be:
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.

##### Share on other sites
Ah ha.

Thanks a lot. I was sooo close, it's just that in XNA the default orientation is along the Y axis, I just had to compensate for it.

Thanks.

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 10
• 9
• 9
• 11
• 11
• ### Forum Statistics

• Total Topics
633686
• Total Posts
3013324
×