Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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 i.e. 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 it's 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) argument 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. It's 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!

share|improve this question
1  
Doesn't Atan2 take the Y value first and then the X value?msdn.microsoft.com/en-us/library/system.math.atan2.aspx . You need to swap your x and y value first. Also have you considered easing your values by interpolation? toValue-currentValue / speed –  Sidar Sep 13 '12 at 14:08
    
Sorry I meant newShuttleAngle - oldShuttleAngle / speed. –  Sidar Sep 13 '12 at 14:14
    
That would only effect the visual orientation and that depends entirely on which way the image for the texture is orientated - I can't see that affected his problem. –  Joe Sep 13 '12 at 14:16
2  
wow great job SomeWritesReserved and everyone else, i am really impressed with this site, the feedback is so fast! its my first post so can someone please tell me what i need to do to properly credit all those who helped? –  Hugh Sep 13 '12 at 14:35
3  
@Hugh Accepting the answer, I don't know if new members can give +rep –  Joe Sep 13 '12 at 14:36
show 8 more comments

1 Answer

up vote 18 down vote accepted

It might be because of how the GamePad's deadzone works. It defaults to GamePadDeadZone.IndependentAxes, which means each axis is checked against the dead zone individually. This tends to cause the input to snap to each axis of the analog thumbstick. Instead, try using GamePadDeadZone.Circular:

newGamePadState = GamePad.GetState(playerIndex, GamePadDeadZone.Circular);

This should give you much smoother control on both axes. Check out the MSDN page and this article by Shawn Hargreaves.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.