XInputDotNetPure.GamePad.SetVibration(XInputDotNetPure.PlayerIndex.One, left, right);
It takes three parameters, the controller, the left vibrate and the right vibrate. Pretty simple, but limiting. As it was the best solution I was going to get, I ignored
the issue of only supporting 360 controllers, and remarkably it was working well with Unity 2019, bar one little detail. Exiting play mode would crash Unity. I wish I could
claim some masterfull debugging for this, but I just went to the settings, had a look at what stood out and changed the CPU mode and it stopped happening. The next problem was
that the only way to stop it vibrating, was to set the vibes to 0. So I built a function to control this a lot more precisely.
public void VibrateFeedback( float left, float right, float duration, bool isDiminishing)
{
XInputDotNetPure.GamePad.SetVibration(XInputDotNetPure.PlayerIndex.One, left, right);
startVibrateTime = Time.timeSinceLevelLoad;
endVibrateTime = startVibrateTime + duration;
IsDiminishing = isDiminishing;
vibrateDuation = duration;
StartVibration = new Vector2(left, right);
}
Essentially, this takes the left, the right, as before, but also takes a time and a bool for whether it diminishes. I used a simple system to create a timer, getting
the timeSinceLevelLoad, adding the duration to that, and then evaulating whether the timeSinceLevelLoad is greater than the when the timer started + duration. Very
rudimentary but it gets the job done. This is essentially a section that sets everything up, and it assess it on update.
private void AssessVibrate()
{
if (Time.timeSinceLevelLoad > endVibrateTime)
{
XInputDotNetPure.GamePad.SetVibration(XInputDotNetPure.PlayerIndex.One, 0, 0);
return;
}
if (IsDiminishing)
{
float evalute = remap(Time.timeSinceLevelLoad, startVibrateTime, 0, 1)
float Mathf.Lerp(StartVibration.x, 0, evalute);
float Mathf.Lerp(StartVibration.y, 0, evalute);
XInputDotNetPure.GamePad.SetVibration(XInputDotNetPure.PlayerIndex.One, vibrateLeft, vibrateRight);
}
}
So as mentioned, it will assess the timer, and return the vibration to nill if nothing is happening. Then it checks if it's diminishing, and if so will remap the
vibration amount from where the vibration started at to 0. This means that it will linearly decrease across the defined duration. This is good for a sudden hit being
quick snappy vibration, whilst a longer hit, such as a burning attack, would be a longer more drawn out vibration. This degree of customizabilty is fairly simple to look at,
but is absoulutely needed whilst working on the game. Giving attacks different vibrations allows the player to haptically tell the difference between them, which is an
often underrated aspect of feedback.
I'm Aled, and I've been working on Games for the last 3 years. I started programming when I was 14, with a computer with no internet access learning from a book. At 16 I went to college, and got a Certificate in Computer Science. I moved onto University of Salford, where I currently am Studying Games Design and Development in my third year.