If you’ve had trouble figuring out the difference between the various forms of input in SteamVR such as EVRButtonId’s, ButtonMasks, TrackedControllers, and TrackedObjects this guide will show you which to use in every situation you come across.
We are going to learn how to receive input from the Vive Controllers and taking action with this input. We will be covering all aspects of the controller including the trigger, grip, touchpad, and haptic feedback.
In the SteamVR heiarchy there are three types of Components. TrackedObjects, Controllers, and TrackedControllers. For basic input you only need to know about TrackedControllers.
Add a SteamVR_TrackedController script to your Controller(left) or Controller (right). Now add a new script to your controller and call it ControllerManager:
We just need to access the event handler for the actual button press and add on our new method to be called whenever the event fires(in this case when the user pushes the trigger). This method will work for all basic forms of input but what if we want to get specific information on touchpad input?
Here, instead of using a TrackedController component you can see that we are using the default trackedObject component. The difference here is that TrackedObject is more abstracted and is meant for use on any object that is tracked by the lighthouse including the HMD. We use it to get an integer representation of our controller which we then assign to SteamVR_Controller.Device to get some controller specific methods for our usage. This way of getting input allows us more latitude in terms of what we can actually get out of our controller at the expense of being hard to read. If we wanted to get trigger input with this same method here is what we would have to do.
Next, we will cover how to map the grip button in addition to adding haptic feedback on press.
The last method of getting input for those so inclined would be to get references to EVRButtonID’s such as in the following example:
We hope that this has been a useful primer on getting controller input using SteamVR. We will be covering ButtonMasks and EVRButtonID’s in more detail in future tutorials so be sure to check back soon.