- Home /
XInput: how do I access vibration on 360 controller?
I'm working on a fighting game, using two 360 controllers for 2 players. To get this to work, I've added xInputPureDotNet to my project. Works perfectly, only minor bug seems to be it detects controller 1 as 2 and vice versa, not a big problem to work around. So, In the sample unity project xInputTest which is included, there is a line accessing vibrate for each motor based on trigger input. Since I don't really fully understand how xinput works, I've been trying to use that example to add force feedback to my own project. The line for vibration is :
Gamepad.SetVibration(playerIndex, state.Triggers.left,state.Triggers.right);
By exposing the state.Triggers.left,state.Triggers.right in the inspector, they appear as normal axis input, maxing out at 1.
However, if I plug in a 1 through code, such as :
var vib1 = 1; var vib2 = 1; Gamepad.SetVibration(playerIndex, vib1,vib2)
(the format is SetVibration(XInputDotNetPure.PlayerIndex,float,float))
Doesn't seem to matter what number I use, all I get is a faint murmur on one controller. The xinput test only seems to take input from one controller (controller 2), so what I want to figure out is:
A: how can I set up the xinputdotnetpure.PlayerIndex for each controller, since the example only seems to work for one? Note: the test detects both controllers, as evidenced in the debug log. Only seems to take input from one though. All I need is to be able to refer to each controller as a PlayerIndex.
B: since the two latter arguments are floats, can't I just set them manually? Why doesn't this work? In the test scene, (using the state.Trigger.right etc.) the vibrate fully works, at least on the one controller. But if I replace with my own floats, just a faint murmur.
If there's anyone out there who knows how to do this, an example would be extremely helpful.. Thanks in advance for any ideas!
Update:figured out the PlayerIndex, it's PlayerIndex.One, PlayerIndex.Two, etc. so now I've got the vibrate basically working, just not as strong as I'd like it to be. Here's the script I'm using, in case anyone's interested:
using UnityEngine;
using XInputDotNetPure;
public class XInputVibrateTest : MonoBehaviour
{
public float testA;
public float testB;
public float testC;
public float testD;
void Update()
{
GamePad.SetVibration(PlayerIndex.Two,testA,testB);
GamePad.SetVibration(PlayerIndex.One,testC, testD);
}
}
then I just set the floats when I want vibration (again, doesn't seem to matter much WHAT I set them to, that's the issue now.. I think it goes 0 to 1, but I can't get the full vibration as in the demo project no matter what I try.)
Answer by Seth-Bergman · Jan 06, 2013 at 03:34 AM
In response to this more recent post, I have just revisited this issue. It seems the problem was the part "PlayerIndex.One" "PlayerIndex.Two"... instead I believe simply replacing "0" and "1" would do it, as in:
GamePad.SetVibration(0,testA,testB);
GamePad.SetVibration(1,testC, testD);
(for controller 3 it would be "2", and for controller 4 it would be "3")
(well, I don't know if that was the issue, doesn't really make sense, but at any rate, all seems to work fine now..)
for a javascript example, see my answer in the link :)
Answer by JtheSpaceC · Dec 14, 2015 at 02:47 PM
The accepted answer didn't help me. I've failed to get this done about a dozen times until today. You need to download a 'using' namespace to get access to the GamePad function.
The download and instructions (scroll down) can be found here. Enjoy! https://github.com/speps/XInputDotNet
Answer by OZAV · Feb 20, 2014 at 02:48 PM
I also have enabled the RUMBLE function, for my FPS game dev, by using the XInputDotNetPure system and it works ok for game pad vibration, but - at the times - i get the permanent vibration that does not stop, after some heavy objects hit the Player, or his camera ... the player has a rigidbody, so, could that be related to the problem, anyone ? Let's shed some light on this, i would not like to think it's a unity bug - i don't think so, in this case.
Your answer
Follow this Question
Related Questions
XInput: vibration on more than 4 360 controller? 0 Answers
Vibration when moving into colliders 1 Answer
Making a Vibraating string. Need Help!! 0 Answers
Xbox one controller vibration 0 Answers
XInput in published builds 2 Answers