Hello,
I want to use both sticks on gamepad. But I got surprised, that my gamepad is recognized as joystick (MSI GC30), as there can be problem with multiple similar divices, I don’t wan’t make binding specificaly to my type.
I want use one stick for moving direction, as well as the second for the aiming direction in the same way.
I found that second stick is Axis Z and Rotation Z (Z & Rz), but generic joystick in Input System does not have these axis by default, it can be found only under specific joystick.
How can I make joystick work in the same way?
I am also priting in settings all available actions with binding by selected scheme, so I need some way that his could be stand preserved.
Turns out you can do something like this to work around the issue.
I’d say that Vector2Composite should be fixed to support using an axis both ways somehow, but it didn’t seem trivial when I tried.
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Layouts;
using UnityEngine.InputSystem.Utilities;
using UnityEngine.Scripting;
#if UNITY_EDITOR
[UnityEditor.InitializeOnLoad]
#endif
[Preserve]
[DisplayStringFormat("{horizontal}/{vertical}")]
public class StickComposite : InputBindingComposite<Vector2> {
[InputControl(layout = "Axis")]
public int horizontal, vertical;
public override Vector2 ReadValue(ref InputBindingCompositeContext context) {
var horizontalAxis = context.ReadValue<float>(horizontal);
var verticalAxis = context.ReadValue<float>(vertical);
return new Vector2(horizontalAxis, verticalAxis);
}
public override float EvaluateMagnitude(ref InputBindingCompositeContext context) {
var value = ReadValue(ref context);
return value.magnitude;
}
#if UNITY_EDITOR
static StickComposite() {
Initialize();
}
#endif
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
static void Initialize() {
InputSystem.RegisterBindingComposite<StickComposite>();
}
}
This is still an issue (and has been for over 12 months now) with current model official xbox controllers. Nintendo pro controllers seem to be ok. Unity please fix this