I am trying to rotate an object towards the mouse. The problem is that the object always rotates slightly in the byte, the extra 45 degrees is excited.
For example, if my mouse is in a position that the object should be placed in the answer, thus rotation value = 0, the object gets to 45 degrees, 270 degrees on the left and thus left Indicates, while it points north / upwards
This is my code:
public override zero update () {base.Update (); GetMousePos (); SetRotation (); } Private Zero GetMousePos () {MouseState ms = Mouse.GetState (); _mousePos.X = ms.X; _mousePos.Y = ms.Y; } Private Zero SetRotation () {Vector 2 Distance = New Vector 2 (); Distance.X = _mousePos.X - (_position.X + (_texture.Width / 2)); Distance. Y = _mousePos.Y - (_position.Y + (_texture.Hyight / 2)); _ Rotation = (float) monastery. Aetan 2 (distance. वाई, distance.x); } Edit: Additional information
These values are displayed when my mouse is on the right side of the screen, the object is prefixed / right Must indicate, but it points north / upwards.
Mouse POS X: 1012
Mouse POS Y: 265
Object POS X: 400275
Object POS Y: 24025
rotation: 0
Editing 2: How to use Public Virtual Zero Draw (Sprintbatch Spreadbatch) {Int. Width = _texture.Width / _columns; Integ Height = _texture.Height / _rows; Rectangle Destrainnection = New Rectangle ((int) _position.X, (int) _position.Y, width, height); Rectangle sourcectactal = new rectangle ((int) ((_ texture.Width / _columns) * _currentFrame), 0, width, height); SpriteBatch.Begin (); Spritebatch.Draw (_texture, destinationRectangle, sourceRectangle, Color.White, _rotation, new vector 2 (width / 2, height / 2), spriteform .a, 0); SpriteBatch.End (); } Edit 3: work to work Secure zero saturation () {mousestate mouse = mouse. Gatestate (); Vector 2 mouseposition = new vector 2 (mouse.x, mouse.W); Vector 2 direction = mouseposition - _position; Direction.Normalize (); _ Rotation = (float) monastery. Ethan 2 (double) direction. Y, (double) direction. X) + 1.5 f; }
Math View the document for Aetan 2: Return value is the angle in the Cartesian plane formed by the X-axis, and a vector (0,0) started from the original, and point Expires on (X, Y).
then will be at least 2 (0,1) pi / 2, or straight up (answer). It means the measurement starts from 0 on the east side (right) and in the rotating counterclockwise direction. It looks like you are expecting 0 degrees straight and straight revolves, so you need to adjust your logic to reflect that.
Comments
Post a Comment