Skip to main content

Input & Controllers

Input

The Input object at xb.core.input provides access to controllers. Interaction callbacks include the resolved target, hit surface, and ray intersection.

For example, to detect which item is selected:

export class ItemSelectionScript extends xb.Script {
onSelectStart(event) {
if (event.target && event.intersection) {
console.log('Item selected:', event.target);
console.log('Hit point:', event.intersection.point);
}
}
}

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: