[XNA] Query with Rotation

Started by
1 comment, last by ryan20fun 13 years, 6 months ago
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]
Advertisement
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.

Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

Have you tried using the xna mathhelper to convert your rotation to radians?

Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

This topic is closed to new replies.

Advertisement