Search Unity

WMR Controller - primary2DAxis of XR returns non-zero Vector2 even at rest

Discussion in 'VR' started by purnapatadia, Dec 5, 2019.

  1. purnapatadia

    purnapatadia

    Joined:
    Jul 20, 2017
    Posts:
    7
    I am working on VR project with WMR headset. I am using UnityEngine.XR to fetch inputs from input devices.

    While working with inputs, I found a weird behaviour of primaryAxis.
    CommonUsages.primary2DAxis returns Non-zero Vector2 even if controller is at rest(i.e. no button/axis are pressed or touched).

    Ideally it should return (0,0) but it is not returning the same. This might be the issue with internal mapping of UnityEngine.XR and WMR controller input
    Can anyone direct me on this?

    I am using Unity version 2019.1.4f1. I also tried with Unity version 2019.3.0f1 but the issue was not resolved.
    Here is a code I used for testing


    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.XR;
    6. public class AxisInput : MonoBehaviour
    7. {
    8.     List<InputDevice> inputDevices;
    9.     InputDeviceRole deviceRole = InputDeviceRole.RightHanded;
    10.     InputFeatureUsage<Vector2> inputFeatureAxis = CommonUsages.primary2DAxis;
    11.     [SerializeField] Vector2 axisValue;
    12.     void Awake()
    13.     {
    14.         inputDevices = new List<InputDevice>();
    15.     }
    16.     void Update()
    17.     {
    18.         InputDevices.GetDevicesWithRole(deviceRole, inputDevices);
    19.         for (int i = 0; i < inputDevices.Count; i++)
    20.         {
    21.             if (inputDevices[i].TryGetFeatureValue(inputFeatureAxis, out axisValue))
    22.             {
    23.                 Debug.Log(axisValue);
    24.             }
    25.         }
    26.     }
    27. }