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:
- WebXR input sources - this includes hand and controllers in Android XR.
MouseController- this becomes enabled in the simulator when User Mode is active.GazeController- this controller represents the center of the screen in Android XR.