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 have a game that the character spins when you press either of the triggers on the xbox remote. Here's the code.

if (gamepadState.IsButtonDown(Buttons.RightTrigger))
        RotationAngle += spinSpeed;

if (gamepadState.IsButtonDown(Buttons.LeftTrigger))
        RotationAngle -= spinSpeed;

what i want to happen is when neither of the triggers are being pressed he rotates back to a rotation angle of 0. I know How to make him go back to 0 when neither triggers are pulled but its too abrupt. How can i make the sprite actually rotate back to an angle of 0?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Try something like this:

private bool isTurning;

public override void Update(GameTime gameTime)
{
    isTurning = false;
    if (gamepadState.IsButtonDown(Buttons.RightTrigger))
    {
        RotationAngle += spinSpeed;
        isTurning = true;
    }

    if (gamepadState.IsButtonDown(Buttons.LeftTrigger))
    {
        RotationAngle -= spinSpeed;
        isTurning = true;
    }

    if (!isTurning && RotationAngle != 0)
    {
        if (RotationAngle > 0)
        {
            RotationAngle -= spinSpeed;
            if (RotationAngle < 0)
                RotationAngle = 0;
        }
        else if (RotationAngle < 0)
        {
            RotationAngle += spinSpeed;
            if (RotationAngle > 0)
                RotationAngle = 0;
        }
    }
}
share|improve this answer
    
thanks very helpful –  Potato Jan 19 '13 at 0:08
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.