Using the Vive Trackers in Unity

From Interaction Station Wiki
Jump to: navigation, search

Before getting started:

Each vive tracker requires its own USB dongle. The number of USB dongles that you can use at one time is limited by the USB bandwidth on the motherboard of the computer. In the HTC.VIVE space in the Interaction Station there is an extra USB PCI card installed that should allow you to connect all the of the dongles at the same time. The trackers seem to work best with the dongles in line of sight from the tracker, so it’s recommended to use the USB extensions that come with the dongles. In most cases the trackers will not work if the headset isn’t connected, there are hacks to get around this but the easiest setup is to connect the headset.
Vive trackers 01 dongle.png

The trackers have a standard 1/4” camera thread on the underside and can be attached to tripods. In the interaction station we also have a few different straps that allow the trackers to be worn on the body, for example on your waist, on your feet or on your hands.

PLEASE NOTE this guide was written for SteamVR 1.10.28, Unity 2019.2 and SteamVR Unity Plugin v2.5.0. Things change rapidly in the VR world so you may have to seek out a more up-to-date guide.

In the Steam VR app:

1.) Pair trackers in SteamVR

https://www.vive.com/us/support/wireless-tracker/category_howto/pairing-vive-tracker.html

2.) Once the tracker is paired, right click the tracker and select manage trackers

Vive trackers 02 manage.png

3.) In the manage tackers section assign tracker to a body part (knees and elbows don’t work yet, so don’t use those)

Vive trackers 03 assign.png

In Unity:

1.)Import Steam VR Unity package (from GitHub or Asset Store)
https://assetstore.unity.com/packages/tools/integration/steamvr-plugin-32647
https://github.com/ValveSoftware/steamvr_unity_plugin

2.)Generate Controller Bindings:
-select window/steamvr input

Steamvr input.png

-click save and generate binding

Vive trackers saveandgenerate.png

-click open binding ui (you may have to select the binding for your specific unity project)

Vive trackers openbinding.png


3.) Manage Bindings
-in binding ui click on current controller to tracker assigned to body part
-It will probably show nothing under Current Binding, so you need to "Create New Binding". In there, you either have to Add Action Pose or Edit Action Poses. There, assign Pose to user/foot/left/pose/raw. Make sure to save your binding.
-repeat for each additional body part

-now you will have bindings for each tracker.

Using the trackers inside of Unity:

-To get an idea of how we might use the trackers in Unity, we can take a look at the SteamVR camera rig. Remove the main camera from your scene and add the camera rig to your scene (Assets/steamVR/Prefabs/[Camera Rig]). If you take a look at controller left game object, it is just a empty game object with a steamvr_behaviour_pose script attached to it. If you take a look at the input source it is currently assigned to the left hand, but you can select a number of other body parts as the input source. The controller left gameObject has a child object with a steamvr_render_model script attached to it. This will handle rendering the model of the controller.
Steamvr controller left.png Steamvr controller left model.png


-to add our own trackers into the scene add an empty game object as a child of the [camera rig], rename it to your body part that you are tracking ie. left foot

-add a steamvr_behavior_pose component to the game object and change the input source to left foot

Steamvr left foot.png

Steamvr left foot source.png

-add a child game object to your left foot, and rename to model

-add a steamvr_render_model component to the model game object. You can leave all the settings as default.

Steamvr left food model.png



-and voila that should be enough to have a tracker in your scene complete with a render model for the tracker. You can repeat these steps to add additional trackers.

More info:

https://github.com/ViveSoftware/ViveInputUtility-Unity/wiki/SteamVR-Input-System-Compatibility
https://medium.com/@sarthakghosh/a-complete-guide-to-the-steamvr-2-0-input-system-in-unity-380e3b1b3311