add notes about checking gamepads and vibration
continuous-integration/drone/push Build is failing Details

main
cosmonaut 2021-03-17 12:25:23 -07:00
parent 4ae140c7c3
commit 18c02a5173
1 changed files with 23 additions and 3 deletions

View File

@ -66,10 +66,30 @@ Inputs.Mouse.RelativeMode = true;
## Gamepad Input
Checking if a gamepad is connected is easy! Gamepads can be connected to slots 0-3.
```cs
if (Inputs.GamepadExists(0))
{
var gamepad = Inputs.GetGamepad(0);
}
```
`GetGamepad` will throw if a gamepad is not connected so you should make sure to check `GamepadExists` before using it.
MoonWorks assumes your gamepad has a left stick, a right stick, and two triggers. The stick axes are represented in the range [-1f, 1f] and the trigger axes in the range [0f, 1f];
```cs
var leftStickHorizontal= Inputs.GetGamepad(0).LeftX;
var rightStickVertical = Inputs.GetGamepad(0).RightY;
var leftTrigger = Inputs.GetGamepad(0).LeftTrigger;
var leftStickHorizontal = gamepad.LeftX;
var rightStickVertical = gamepad.RightY;
var leftTrigger = gamepad.LeftTrigger;
```
You can also set controller vibration by providing left and right motor amounts and a duration in milliseconds.
```cs
var leftMotorAmount = 0.2;
var rightMotorAmount = 0.5;
var durationInMilliseconds = 10;
gamepad.SetVibration(leftMotorAmount, rightMotorAmount, durationInMilliseconds)
```