Search Unity

XRNodeState's TryGetAngularVelocity not working properly for me?

Discussion in 'AR/VR (XR) Discussion' started by VR_Unity_Account, Jul 13, 2018.

  1. VR_Unity_Account

    VR_Unity_Account

    Joined:
    Aug 17, 2017
    Posts:
    22
    Hey, all. I'm attempting to create a grabbing and throwing script using only Unity's built-in XR utilities, in order to allow for easy cross-platform play. Velocity calculations are great. No complaints there. However, when attempting to incorporate angular velocity to my throws, things behave strangely.

    The angular velocity does not seem to take the orientation of the hand itself into account, making accurate rotations only possible when the player's hand is facing global forward.

    Here's what I've got as a test script. It is applied to a Rigidbody floating in the space so I can see what it does when I rotate my hand.

    Code (CSharp):
    1. public class TestVelocityScript : MonoBehaviour {
    2.  
    3.     [SerializeField] private bool LeftHand;
    4.  
    5.     [SerializeField] private Vector3 HandVelocity;
    6.     [SerializeField] private Vector3 HandAngularVelocity;
    7.  
    8.     private Rigidbody RB;
    9.  
    10.     // Use this for initialization
    11.     void Start () {
    12.         RB = GetComponent<Rigidbody> ();
    13.     }
    14.    
    15.     // Update is called once per frame
    16.     void FixedUpdate ()
    17.     {
    18.         List<XRNodeState> nodes = new List<XRNodeState>();
    19.         InputTracking.GetNodeStates (nodes);
    20.  
    21.         foreach(XRNodeState ns in nodes)
    22.         {
    23.             if (LeftHand)
    24.             {
    25.                 if(ns.nodeType == XRNode.LeftHand)
    26.                 {
    27.                     ns.TryGetVelocity(out HandVelocity);
    28.                     ns.TryGetAngularVelocity (out HandAngularVelocity);
    29.                 }
    30.             }
    31.  
    32.             if (!LeftHand)
    33.             {
    34.                 if(ns.nodeType == XRNode.RightHand)
    35.                 {
    36.                     ns.TryGetVelocity(out HandVelocity);
    37.                     ns.TryGetAngularVelocity (out HandAngularVelocity);
    38.                 }
    39.             }
    40.  
    41.         }
    42.         RB.angularVelocity = HandAngularVelocity;
    43.     }
    44. }
    Is there a workaround for this?
    Thanks!
     
  2. VR_Unity_Account

    VR_Unity_Account

    Joined:
    Aug 17, 2017
    Posts:
    22