Skip to content

controllers

The controllers component provides a complete system for VR controller interaction in A-Frame scenes. It automatically creates and manages left and right hand controllers with raycasters, visual cursors, and event handling for all controller buttons.

Example

Below is an example of adding controllers to a scene. The controllers will automatically appear when using a compatible VR headset with controllers.

Props

PropertyTypeDefaultDescription
leftEnabledbooleantrueWhether to enable the left controller
rightEnabledbooleantrueWhether to enable the right controller
leftColorcolor#cfc7c6Color of the left controller ray and cursor
rightColorcolor#cfc7c6Color of the right controller ray and cursor
cursorSizenumber0.01Size of the cursor sphere at the end of the ray (in meters)
raycastLengthnumber10Maximum length of the controller raycast (in meters)

Controller Events

The component forwards controller button events to intersected objects. Any object with class "interactive" or "clickable" can receive these events:

EventDescription
triggerdownFired when trigger button is pressed
triggerupFired when trigger button is released
gripdownFired when grip button is pressed
gripupFired when grip button is released
abuttondownFired when A button is pressed (right hand)
abuttonupFired when A button is released
bbuttondownFired when B button is pressed (right hand)
bbuttonupFired when B button is released
xbuttondownFired when X button is pressed (left hand)
xbuttonupFired when X button is released
ybuttondownFired when Y button is pressed (left hand)
ybuttonupFired when Y button is released
menudownFired when menu button is pressed
menuupFired when menu button is released
trackpaddownFired when trackpad/thumbstick is pressed
trackpadupFired when trackpad/thumbstick is released

Usage Tips

Making Objects Interactive

For advanced interactivity with visual feedback and custom event handling, consider using the vr-interactive component:

html
<!-- Basic vr-interactive usage -->
<a-entity 
  geometry="primitive: box" 
  material="color: blue"
  vr-interactive
></a-entity>

<!-- Customized vr-interactive with specific button handling -->
<a-entity
  geometry="primitive: sphere"
  material="color: green"
  vr-interactive="
    enabledButtons: trigger, grip;
    highlightColor: #FFFF00;
    scaleOnClick: 0.8;
  "
></a-entity>

For more basic event handling, you can use A-Frame's event system:

html
<a-entity id="myObject" class="interactive" 
          geometry="primitive: box" 
          material="color: blue"
          event-set__triggerdown="_event: triggerdown; material.color: yellow"
          event-set__triggerup="_event: triggerup; material.color: blue">
</a-entity>