Bounce balls on the real room
Updated
XR Planes with an XR Plane Collider and XR Meshes with an XR Mesh Collider make the detected room solid, drawn as translucent blue as in the runtime AR Placement demo. Balls drop every two seconds and bounce on the real floor and furniture.
This one needs AR: enter AR on a device that detects planes or room meshes and the balls land on real surfaces. On a desktop nothing is detected, so a virtual floor catches them.
Bounce balls on the real room
#pragma lifecycle(startup)
function wait(ms) { return new Promise((done) => delay(done, ms));}
async function startup() { const planes = findEntity('XR Planes').getComponent(XRPlanesComponent); const meshes = findEntity('XR Meshes').getComponent(XRMeshesComponent); on('room', ({ eventType, data }) => { if (eventType === EventType.XRPlanes.Detected || eventType === EventType.XRMeshes.Detected) log('Found', data.label ?? 'a surface', `(${planes.count} planes, ${meshes.count} meshes)`); }); log(`Surfaces now: ${planes.count} planes, ${meshes.count} meshes`);
const colors = ['#f59e0b', '#38bdf8', '#a78bfa', '#34d399']; for (let i = 0; ; i++) { const ball = spawn('Ball', { position: { x: Random.range(-0.6, 0.6), y: 1.6, z: Random.range(-0.6, 0.6) }, enabled: true }); ball.getComponent(StandardMaterialComponent).setProps({ color: colors[i % colors.length] }); delay(() => destroy(ball), 12000); await wait(2000); }}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.
XrRoomColliders.xrproj