Last active
April 1, 2019 10:22
-
-
Save daemon3000/8af19e8fcfe11ec072538c51f0157358 to your computer and use it in GitHub Desktop.
Controller vibration support for Unity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. Get the InputManager plugin from: https://github.com/daemon3000/InputManager | |
// 2. Get the XInput wrapper unitypackage from: https://github.com/speps/XInputDotNet/releases | |
// 3. Import the two plugins into your project. | |
// 4. Open the InputAdapter.cs file from the InputManager plugin and add the following: | |
// 4.1. Add this at the top of the file: | |
using XInputDotNetPure; | |
// 4.2. Add this at the end of the [Static Accessors] region: | |
// leftMotor and rightMotor should be a value between 0 and 1 | |
public static void Vibrate(PlayerID playerID, float leftMotor, float rightMotor) | |
{ | |
GamePad.SetVibration((PlayerIndex)((int)playerID), leftMotor, rightMotor); | |
} | |
// 5. Test if vibrations work like this: | |
private void Update() | |
{ | |
float leftTrigger = InputAdapter.GetTriggerAxis(InputTriggerAxis.Left); | |
float rightTrigger = InputAdapter.GetTriggerAxis(InputTriggerAxis.Right); | |
InputAdapter.Vibrate(PlayerID.One, leftTrigger, rightTrigger); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment