Jump to content
  • Advertisement
Sign in to follow this  

[XNA] Query with Rotation

This topic is 2808 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

Ok, hopefully a qq. I have a sprite, which I am rotating to face the mouse.

public void MoveToMouse(Point MousePosition)
* 1. Find out how much we need to rotate
* 2. Find out what the Vector is and Normalise it

Vector2 StartDir = new Vector2(0, -1);
float rot = (float)Math.Atan2(MousePosition.Y - Center.Y,
Center.X - MousePosition.X);

rot = -(float)(rot + MathHelper.ToRadians(90.0f));
PlayerStatistics.Rotation = rot;

Matrix rotMat = Matrix.CreateRotationZ(rot);
Vector2 MoveDir = Vector2.Transform(StartDir, rotMat);
MoveDirection = MoveDir;


However, I am sure there is a better way of doing this if I want to save the rotation(in Radians) always as Positive! At the moment I keep getting values such as -0.4f etc.

(p.s it also doesnt quite work, there is a sligh offset :S) Anyone see where i am going wrong?

The reason I want to do this is because I need to be able to determine the compass direction the sprite is facing.

[Edited by - Andy474 on October 16, 2010 6:36:12 AM]

Share this post

Link to post
Share on other sites
Have you tried looking at the xna creaters site for there
2d ai, becouse the examples have a turn to face method you could probably use with
Minimal effort.

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!