Skip to main content

Inputs

Input

The Input object available at xb.core.input provides access to controllers and raycasting results. Intersection results can be queries using the intersectionsForController property which maps controllers to raycast results. Raycast results are automatically updated when the controller begins selecting.

For example, to detect which item is selected:

export class ItemSelectionScript extends xb.Script {
onSelectStart(event) {
const controller = event.target;
const intersections = xb.core.input.intersectionsForController(controller);
if (intersections.length > 0) {
console.log('Item selected:', intersections[0].object);
}
}
}

When a controller begins selecting, XRInput also sets controller.userData.selected to true. This can be used to loop over controllers which are selecting. For example:

export class ItemSelectionScript extends xb.Script {
update() {
const controllers = xb.core.input.controllers;
for (const controller of controllers) {
if (controller.userData.selected) {
handleController(controller);
}
}
}
}

Controllers

XR Blocks currently includes the following controllers: