Cant get a body’s rotation value to follow the mouse pointer.

Topics: Developer Forum, User Forum
Dec 23, 2013 at 6:50 PM
Edited Dec 24, 2013 at 10:54 AM
Here is what’s in my HandleKeyboard() method that is called from the Game1 Update method.
            MouseState mState = Mouse.GetState();
            // the Vector2 that will hold the angle from the player to the mouse pointer.
            Vector2 mDirection = new Vector2(0, 0);

                // Get the current mouse position from the state update in the beginning of this method.
                Vector2 mPosition = new Vector2(mState.X, mState.Y);
                // Subtract the potsition of the player fromthe mouse pointer to get the exact angle in a vector2
                mDirection = mPosition - arrow.Position;

                // Control Rotation
                arrow.FixedRotation = true;
                // display the arrow in the rotation gathered above.
                arrow.Rotation = (float)Math.Atan2(mDirection.Y, mDirection.X);
From what I have read, this seems like the exact right thing to have the arrow look at my pointer. However when I rotate the mouse around the pointer it really doesn’t work properly.

It's hard to explain so here is a youtube video displaying what’s happening

EDIT: have also added in a few lines to normalize the mDirection. but it still doesn't affect the behaviour unfortunately.

I really hope you can tell me what’s going wrong.
Dec 25, 2013 at 10:02 AM
SOLVED

I stupidly forgot to convert the position of the mouse pointer to sim units.

apologies