Jump to content
  • Advertisement
Sign in to follow this  
MrD 588

Angle from Vector

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by MrDoom
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?
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!