Flash the screen when the player is hurt
Updated
On player/hurt, the camera’s Vignette darkens sharply and eases back with a tween, while its Glitch effect tears the image for 400 ms.
Press Hurt to flash the screen. Drag to orbit the camera, scroll to zoom.
Flash the screen when the player is hurt
#pragma lifecycle(startup)
let vignette;let glitch;let pulse = null;let quiet = null;
function startup() { const eye = findEntity('Main Camera'); vignette = eye.getComponent(VignetteEffectComponent); glitch = eye.getComponent(GlitchEffectComponent); glitch.setProps({ active: false });
on('player/hurt', (data) => { const amount = Math.min(1, (data?.damage ?? 10) / 50); const peak = 0.5 + 0.45 * amount;
if (pulse) pulse.stop(); pulse = Tween.value(peak, 0.5, (value) => vignette.setProps({ darkness: value }), { duration: 0.6, ease: Ease.OutQuad, });
glitch.setProps({ active: true, strength: [0.2, 0.4 + 0.6 * amount] }); if (quiet) quiet(); quiet = delay(() => glitch.setProps({ active: false }), 400); });}How it works
Section titled “How it works”The script is explained step by step in Flash the screen when the player is hurt.
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.
HurtFeedback.xrproj