Musical stepping stones
Updated
Five stones each carry a child Positional Audio Tone: bouncing balls land on them, and the stones’ collision events play each one’s note from where it sits.
With your sound on, click once to start the audio, then listen: every bounce plays the stone's note, and the log shows its frequency. Run the example again to replay. Drag to orbit the camera, scroll to zoom.
Musical stepping stones
#pragma lifecycle(startup)
const voices = new Map();
function startup() { for (const note of ['C4', 'D4', 'E4', 'G4', 'A4']) { const stone = findEntity(`Stone ${note}`); const voice = stone.children.find((child) => child.name === 'Voice'); voices.set(stone.entityId, { note, tone: voice.getComponent(PositionalAudioToneComponent) }); }
on('stone', (event) => { if (event.eventType !== EventType.PhysicsCollider.CollisionEnter) return; const entry = voices.get(event.entityId); if (!entry) return; entry.tone.play(entry.note, 0.3); log(`${entry.note}: ${AudioToneComponent.frequencyOf(entry.note).toFixed(1)} Hz`); });}How it works
Section titled “How it works”The script is explained step by step in Musical stepping stones.
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.
SteppingStones.xrproj