Explosions shake by distance
Updated
Click a barrel to blow it up: the guide’s ExplosionShake script plays the camera’s Tremor effect, strong for the barrels near you and weaker for the far ones.
Click the nearest barrel, then the farthest one, and compare how hard the view shakes. Drag to orbit the camera, scroll to zoom.
Explosions shake by distance
#pragma lifecycle(startup)
const RANGE = 25; // beyond this, an explosion does not shake the view
function startup() { const cam = CameraDirector.main; if (!cam) return; const tremor = cam.getComponent(CameraTremorEffectComponent); const here = new THREE.Vector3();
// Another script emits 'bomb/exploded' with { position: { x, y, z } }. on('bomb/exploded', (data) => { cam.getWorldPosition(here); const distance = here.distanceTo(data.position); if (distance > RANGE) return; tremor.play(1 - distance / RANGE); });}#pragma lifecycle(startup)
function startup() { on('barrel/click', async (event) => { if (event.eventType !== EventType.Selectable.Select) return; const barrel = findEntity(event.entityId); if (!barrel) return; const position = barrel.getWorldPosition(new THREE.Vector3()); await Tween.to(barrel.scale, { x: 1.6, y: 0.2, z: 1.6 }, { duration: 0.12, ease: Ease.OutCubic }); destroy(barrel); log(`${barrel.name} exploded ${position.distanceTo(camera.position).toFixed(1)} m away`); emit('bomb/exploded', { position }); });}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.
ExplosionTremor.xrproj