Spectate the selected car
Updated
A Third Person camera that follows whichever car you click: the script passes the clicked entity as the controller target.
Click a car to follow it. Drag to orbit it, scroll to zoom.
Spectate the selected car
#pragma lifecycle(startup)
const RACERS = ['Red Car', 'Blue Car', 'Green Car'];
function startup() { const follow = findEntity('Spectator Cam').getComponent(ThirdPersonControllerComponent);
on('racers', (event) => { if (event.eventType !== EventType.Selectable.Select) return; findEntity(event.entityId)?.getComponent(SelectableComponent)?.setSelected(false); // so the next click selects it again const car = findEntity(event.entityId); if (car && RACERS.includes(car.name)) { follow.setProps({ target: car, distance: 7 }); } });}How it works
Section titled “How it works”The script is explained step by step in Spectate the selected car.
Open it in XR Creator
Section titled “Open it in XR Creator”Download the project file below, then import it in XR Hub with Projects › New › Import, as described in Projects and templates. It opens in XR Creator with the same scene you see running above, each script already attached to its Behavior entity. From there you can edit the scripts, adjust components and their props, preview your changes, and deploy the result as a world of your own.
SpectateSelected.xrproj