Sign in to follow this  

[XNA] Query with Rotation

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this