Independent of SDK
With this method, you won’t have to install third party packages like SteamVR or Oculus Avatars to gain control of the controllers. We can write code once and still work on all headsets supported by Unity.
References to controllers
Before you being, import the XR library:
We then can get references to the controllers like this:
Xnode left = XRNode.LeftHand; Xnode right = XRNode.RightHand; Xnode head= XRNode.CenterEye;
Then get the localPosition and localRotation of the controllers be calling a method from input tracking:
Vector3 leftHandPosition = InputTracking.GetLocalPosition(left); Quaternion leftHandRotation = InputTracking.GetLocalRotation(left);
You can then use these transforms to control what ever you want in your game. Write a script to control a cube’s transform to match the tracking and you’ve got yourself new hands!