XR Input: primary2DAxis always returns 0
Trying to use XR Input and working on joystick-based locomotion but trying to access the joystick always comes up 0. I'm using Oculus Rift Touch controllers (Not Rift S or Quest) and the devices and features needed are present.
Here's my code for reference: private List leftHands = new List(); private InputDevice rightHand;
private void Update()
{
// We get our hand(s) first before attempting to locomote
GetHands();
Locomotion();
}
private void GetHands()
{
InputDevices.GetDevicesAtXRNode(XRNode.LeftHand, leftHands);
}
private void Locomotion()
{
if (leftHands.Count == 0)
return;
if (!leftHands[0].isValid)
return;
Vector2 movementVector;
if (leftHands[0].TryGetFeatureValue(CommonUsages.primary2DAxis, out movementVector))
{
// Shows that value is always zero
print($"Left Joystick Values: {movementVector}");
if (Mathf.Abs(movementVector.x) >= 0.2f || Mathf.Abs(movementVector.y) >= 0.2f)
{
Move(movementVector);
}
}
}
Comment
Answer by milliepuss · May 24, 2020 at 08:23 AM
your code is OK... maybe you haven't put the HMD on after hitting Play? Have a look at the Console after taking off the HMD and see those Vector2 values. (also, get GetHands out of Update and into Start... you don't need to return a list of InputDevices every frame).