From 18c02a5173e093626a57842c841005dd951f2e11 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Wed, 17 Mar 2021 12:25:23 -0700 Subject: [PATCH] add notes about checking gamepads and vibration --- content/Input/_index.md | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/content/Input/_index.md b/content/Input/_index.md index 5e0daae..29f3a58 100644 --- a/content/Input/_index.md +++ b/content/Input/_index.md @@ -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) ```