Controller Input

In InstantVR you can access controller input in a device-independent way. In this way you can use input from VR controllers or game controllers with the same code.

You can look at the InputHandler.cs script, found in Assets/InstantVR/Demo/GroceryStore/Scripts for an example of the use of the controller input code.


You can get access to the controller input using the GetController function is the Controllers class:

ControllerInput controller = Controllers.GetController(0);

Only one controller is supported, so the value passed to GetController should always be 0.

The controller input is always split in two sides: the left side which is controlled with the left hand and the right side controlled by the right hand.

ControllerInputSide leftHandSide = controller.left;
ControllerInputSide rightHandSide = controller.right;


Each controller input side has a list of parameters corresponding to possible buttons on the controller side. These can be read to get the current state of that button:

public class ControllerInputSide {
   public float stickHorizontal;
   public float stickVertical;
   public bool stickButton;
   public bool stickTouch;
   public bool up;
   public bool down;
   public bool left;
   public bool right;

   public bool[] buttons = new bool[4];

   public float trigger1;
   public float trigger2;

   public bool option;

Next to that, you can also use the GetButton function which returns a boolean which is true when the given button is pressed:

bool trigger1IsPressed = GetButton(ControllerInput.Button.Trigger1);


You can use the OnButtonDownEvent and OnButtonUpEvent to call a function when a controller input button has been pressed or released. The function will be called with the button identification of the button pressed:

leftHandSide.OnButtonDownEvent += OnButtonDownLeft;
leftHandSide.OnButtonUpEvent += OnButtonUpLeft;

private void OnButtonDownLeft(ControllerInput.Button buttonID) {
   Debug.Log(buttonId + " is pressed");

private void OnButtonUpLeft(ControllerInput.Button buttonID) {
   Debug.Log(buttonId + " is released");

Simulating input

For the buttons it is possible to simulate pressing them using the function PressButton:


Mapping of the controller input

As the number and types of buttons for different devices differ, not all buttons are used for each controller input device.

You can find information about the mapping of the controller buttons to the Controller Input code at the support page for the device.