Automatically Differentiate Between Left- & Right Stick Inputs for HOSAS Use
By default Unity does not recognize the difference between left- and right handed fight sticks.
There is however a suitable system for XR-Controllers in the form of Configuration Usage Tags
.
These scripts automatically assign a side to Thrustmaster T16000M sticks by reading the value of the little switch on the bottom.
Additionally the sides get updated automatically at runtime, should the switch be flipped again - or another device be plugged in.
Just place the scripts somewhere in your project.
In the Input Actions Window, for each binding - the side can be chosen:
<HID::Thrustmaster T.16000M>{leftHand}/stick
<HID::Thrustmaster T.16000M>{rightHand}/hat
Additionally the value of leftRightSwitch
can be read directly:
// https://docs.unity3d.com/Packages/[email protected]/api/UnityEngine.InputSystem.InputAction.html
InputAction changeHandAction = new InputAction(binding: "<HID::Thrustmaster T.16000M>/leftRightSwitch");
changeHandAction.performed += (_ => foo()); // Right Side
changeHandAction.canceled += (_ => bar()); // Left Side
changeHandAction.Enable();
Though I see no reason to do so.
NOTE: To get notified of ANY change in stick side, use InputActionType.PassThrough
.
For now this ONLY works for Thrustmaster T16000M joysticks. However, support for other sticks can be added:
Analogous to SidedTM16KM.cs
:
- Create an Input Layout Override
- Add a binding using the
SidedStickInitialize
Attribute - Create a registerStick method
- Add the method using the
SidedStickRegistrate
Attribute
If you do so, please create a pull request, so we can all benefit.
This was originally based on two Unity Forum posts: 1, 2, though some quality of life features, as well as some bug-fixes, are entirely my own.