Xbox Controller Vibration


In the previous tutorial we looked at how to get input from the user with an Xbox 360 controller. In this tutorial we will take a look at a cool feature of Xbox controllers: vibration.

Xbox Controller Vibration

Once again, the XNA people have made a possibly complicated task very easy to do. Setting a controller to vibrate is very easy. The line of code that will allow us to do this is shown below:

GamePad.SetVibration(PlayerIndex.One, 1.0f, 1.0f);

The values in this function are, from left to right, the index of the player whose controller you want to vibrate, the amount of vibration that should happen in the left vibration motor, and last, the amount of vibration that should happen in the right vibration motor. For these two parameters, the values can range from 0 to 1, where 0 means no vibration at all, and 1 means full vibration.

The values of the two different motors do not have to be the same. In fact a lot of games use this to their advantage. If you get hit on the left side, the left motor vibrates more. If you get hit on the right side, the right motor vibrates more.

One thing to remember is that once a controller is told to vibrate, it won't stop until you set it back to 0. Make sure you set it up so that after a little while, the vibration gets set back to 0 or you will drive players crazy.

What's Next?

From here, I would recommend checking out how to do player input from a keyboard or mouse if you haven't already seen how to do that.

Troubleshooting.png Having problems with this tutorial? Try the troubleshooting page!