public void MoveToMouse(Point MousePosition) { /*Todo: * 1. Find out how much we need to rotate * 2. Find out what the Vector is and Normalise it */ //1. 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; //2. Matrix rotMat = Matrix.CreateRotationZ(rot); Vector2 MoveDir = Vector2.Transform(StartDir, rotMat); MoveDir.Normalize(); 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]