-
Notifications
You must be signed in to change notification settings - Fork 0
Controller Events
[VRTK_ControllerEvents]
The Controller Events script is attached to a Controller object within
the [CameraRig] prefab and provides event listeners for every button
press on the controller (excluding the System Menu button as this
cannot be overriden and is always used by Steam).
When a controller button is pressed, the script emits an event to denote that the button has been pressed which allows other scripts to listen for this event without needing to implement any controller logic.
The script also has a public boolean pressed state for the buttons to allow the script to be queried by other scripts to check if a button is being held down.
When a controller button is released, the script also emits an event denoting that the button has been released.
The controller touchpad has two states, it can either be touched
where the user simply presses their finger on the pressure sensitive
pad or it can be clicked where the user presses down on the pad until
it makes a clicking sound.
The Controller Events script deals with both touchpad touch and click events separately.
There are two button axis on the controller:
- Touchpad touch position, which has an x and y value depending on where the touchpad is currently being touched.
- Trigger button, which has an x value depending on how much the trigger button is being depressed.
There are two additional events emitted when either the Touchpad axis or the Trigger axis change their value which can be used to determine the change in either of the axis for finer control such as using the Touchpad to move a character, or knowing the pressure that the trigger is being pressed.
The Touchpad Axis is reported via the TouchpadAxis payload variable
which is updated on any Controller Event.
The Trigger Axis is reported via the buttonPressure payload variable
which is updated on any Controller Event. Any other button press will
report a button pressure of 1 or 0 as all other buttons are digital
(they are either clicked or not clicked) but because the Trigger is
analog it will report a varying button pressure.
The amount of fidelity in the changes on the axis can be
determined by the axisFidelity parameter on the script, which is
defaulted to 1. Any number higher than 2 will probably give too
sensitive results.
The event payload that is emitted contains:
- controllerIndex: The index of the controller that was used.
- buttonPressure: A float between 0f and 1f of the amount of. pressure being applied to the button pressed.
- touchpadAxis: A Vector2 of the position the touchpad is touched at.
There are also common action aliases that are emitted when controller buttons are pressed. These action aliases can be mapped to a preferred controller button. The aliases are:
- Toggle Pointer: Common action of turning a laser pointer on/off
- Toggle Grab: Common action of grabbing game objects
- Toggle Use: Common action of using game objects
- Toggle Menu: Common action of bringing up an in-game menu
Each of the above aliases can have the preferred controller button mapped to their usage by selecting it from the drop down on the script parameters window.
When the set button is pressed it will emit the actual button event as well as an additional event that the alias is "On". When the set button is released it will emit the actual button event as well as an additional event that the alias button is "Off".
Listening for these alias events rather than the actual button events means it's easier to customise the controller buttons to the actions they should perform.
An example of the VRTK_ControllerEvents script can be viewed in
the scene SteamVR_Unity_Toolkit/Examples/002_Controller_Events and code examples
of how the events are utilised and listened to can be viewed in the
script SteamVR_Unity_Toolkit/Examples/Resources/Scripts/VRTK_ControllerEvents_ListenerExample.cs
- Home
- Quick Start
- FAQ/Troubleshooting
- Prefabs
-
Scripts
- Controllers
- Pointers
- Movement
- Interactions
- Examples