So here are my setup, I have a Vector3 input and a float input.
Thing is, the Vector3 input performed when I press the key and release the key, so that I’m updated with 0,0,1 and 0,0,0 value.
But the float input only updates me when I press the button, and I would like it to perform a 0 when I release the key.
FYI this is the Vector3 composite class I created.
[InitializeOnLoad]
public class Vector3Composite : InputBindingComposite<Vector3>
{
[InputControl(layout = "Button")] public int forward = 0;
[InputControl(layout = "Button")] public int backward = 0;
[InputControl(layout = "Button")] public int left = 0;
[InputControl(layout = "Button")] public int right = 0;
[InputControl(layout = "Button")] public int up = 0;
[InputControl(layout = "Button")] public int down = 0;
public override Vector3 ReadValue(ref InputBindingCompositeContext context)
{
bool forwardIsPressed = context.ReadValueAsButton(forward);
bool backwardIsPressed = context.ReadValueAsButton(backward);
bool leftIsPressed = context.ReadValueAsButton(left);
bool rightIsPressed = context.ReadValueAsButton(right);
bool upIsPressed = context.ReadValueAsButton(up);
bool downIsPressed = context.ReadValueAsButton(down);
Vector3 result = Vector3.zero;
result.x = rightIsPressed ? 1 : (leftIsPressed ? -1 : 0);
result.y = upIsPressed ? 1 : (downIsPressed ? -1 : 0);
result.z = forwardIsPressed ? 1 : (backwardIsPressed ? -1 : 0);
return result;
}
static Vector3Composite()
{
InputSystem.RegisterBindingComposite<Vector3Composite>();
}
[RuntimeInitializeOnLoadMethod]
static void Init() {} // Trigger static constructor.
}