Public Group

# [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.

## Recommended Posts

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

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]

##### 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 on other sites
Have you tried using the xna mathhelper to convert your rotation to radians?

1. 1
2. 2
Rutin
18
3. 3
4. 4
5. 5

• 14
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631429
• Total Posts
3000033
×