Overdrive with damage
Updated
An Audio Distortion Filter on the music switches on below 60 health and grows harder with each hit, in four steps; healing switches it off again.
With your sound on, press Take a hit a few times: past the third hit the beat starts to crunch, harder at each hit. Press Heal to clean it. The beat is a short loop generated for this example. Drag outside the panel to orbit the camera.
Overdrive with damage
#pragma lifecycle(startup)
let grit;let bar;let label;let health = 100;
function apply() { bar.setValue(health); if (health > 60) { grit.setEnabled(false); label.setProps({ text: 'Clean: distortion off', color: '#34d399' }); return; } grit.setEnabled(true); // Rounded to steps, because distortion changes apply at once. const amount = Math.round(((60 - health) / 60) * 4) / 4; grit.setProps({ amount }); label.setProps({ text: `Distortion amount ${amount}`, color: '#f87171' });}
function startup() { grit = findEntity('Music').getComponent(AudioDistortionFilterComponent); bar = findEntity('Health').getComponent(UIProgressComponent); label = findEntity('Grit').getComponent(UILabelComponent);
on('player/hit', (event) => { if (event.eventType !== EventType.UIButton.Press) return; health = Math.max(0, health - 20); apply(); }); on('player/heal', (event) => { if (event.eventType !== EventType.UIButton.Press) return; health = 100; apply(); }); apply();}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.
DamageGrit.xrproj