Skip to content

Instantly share code, notes, and snippets.

@daemon3000
Last active April 1, 2019 10:22
Show Gist options
  • Save daemon3000/8af19e8fcfe11ec072538c51f0157358 to your computer and use it in GitHub Desktop.
Save daemon3000/8af19e8fcfe11ec072538c51f0157358 to your computer and use it in GitHub Desktop.
Controller vibration support for Unity
// 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