xbox thumbstick used to rotate sprite, basic formula makes it "stick" or feel "sticky" at 90 degree intervals! how do get smooth rotation?

Posted by Hugh on Game Development See other posts from Game Development or by Hugh
Published on 2012-09-13T14:01:35Z Indexed on 2012/09/13 15:51 UTC
Read the original article Hit count: 320

Filed under:
|
|
|
|

Context: C#, XNA game

I am using a very basic formula to calculate what angle my sprite (spaceship for example) should be facing based on the xbox controller thumbstick ie. you use the thumbstick to rotate the ship!

in my main update method:

shuttleAngle = (float) Math.Atan2(newGamePadState.ThumbSticks.Right.X, newGamePadState.ThumbSticks.Right.Y);

in my main draw method:

spriteBatch.Draw(shuttle, shuttleCoords, sourceRectangle, Color.White, shuttleAngle, origin, 1.0f, SpriteEffects.None, 1);

as you can see its quite simple, i take the current radians from the thumbstick and store it in a float "shuttleAngle" and then use this as the rotation angle (in radians) arguement for drawing the shuttle.

For some reason when i rotate the sprint it feels sticky at 0, 90, 180 and 270 degrees angles, it wants to settle at those angles. its not giving me a smooth and natural rotation like i would feel in a game that uses a similar mechanic. PS: my xbox controller is fine!

© Game Development or respective owner

Related posts about XNA

Related posts about c#