Hi. From reading some prior posts, I understand that Unity under Windows samples joystick data using the Raw Input API rather than DirectInput, which may be fine for keyboard and mouse support, but for gamepads/joysticks means that devices callibrated and tested to work correctly in Windows Control Panel and other games, may well behave erratically in Unity.
The first gamepad I tried has severe axis issues (X Axis and Y Axis report -1 at rest and 1 when pushing fully any direction). For reference this is a Thrustmaster Dual Analog 3 gamepad running windows latest drivers. I assume that devs go out and buy a device known to work well under Unity for their regular development, but I dont see how we can ask end users to do that.
It is disappointing that a game engine of Unity’s importance and popularity does not support gamepads well on PC. Oddly they appear to have dropped earlier support for a DirectInput alternative API.
Since it seems no support is forthcoming on this, I guess I’ll spend this weekend writing an alternative input plugin to extend support for DirectInput and possibly XInput device reading.
Okay I’ve put together a native input plugin to obtain joystick/gamepad data via DirectInput under Windows. Its still a bit bare-bones but it works great for movement and aiming based on the analogue sticks. I was thinking if I have time of adding force feedback support, but I’m finding though that since Unity is also sampling the same devices I’m unable to obtain the exclusive access I’d need for those effects. Anyone know how to tell Unity to not access joystick devices?
Hi I am having what appears to be this same issue with the joystiq reporting -1 when centered and +1 when pushed to an extremity. Any chance you could share any insights you have gained about the issue or source if you are able. I’m not concerned with force feedback or other features. I really just need to read the analogue data correctly.
Yeah, okay. I’ll share what I’m using in my demo project here:
Note this is providing DirectInput access to gamepads and joysticks via a native plugin, so its only going to be useful under Windows.
Where you would previously use
Input.GetAxis(“Horizontal”)
Input.GetAxis(“Vertical”)
now you can use:
DxInputManager.Instance.GetValue(“X Axis”)
DxInputManager.Instance.GetValue(“Y Axis”)
If you are interested in reading more than one input device, GetValue can be called with the desired device number as an additional parameter. You can query the number of devices, and enumerate each of their controls and control types, with the idea of letting players best customize their input bindings to the capabilities of whatever devices are found. The DxInputManager was meant to be extended to manage this kind of input binding, but I didnt get to that yet so I’ll leave that to you to extend if needed. For quick testing though, you should see in the debug log a printed list of all the devices and their available controls.
I also have the source for the DirectInput plugin if you need it to modify or recompile that. Just let me know.
With very little change (defining two separate devices, one for X and one for Y, or defining some configuration code for a muxed device), your library can be called with Input.GetAxis(“Horizontal”) and Input.GetAxis(“Vertical”) again
In the end i’ve solved the problem.
To Know the list of the command for your device just write:-
Debug.Log(DxInput.DeviceControlName(i, j));
Where i is the number of the device connected to the computer and j is the name of the control of the device…
DxInputManager.Instance.GetValue(“Z Rotation”) for the X Axis of the right stick
DxInputManager.Instance.GetValue(“Slider”) for the Y Axis of the right stick