Sparks where something hits hard
Updated
A falling crate copies a disabled Sparks entity at the contact point with spawn whenever it lands faster than 4 m/s, and destroys the copy a second later.
Watch the crate land in a burst of sparks. Grab it, lift it high and let it drop to see them again. Drag elsewhere to orbit the camera.
Sparks where something hits hard
#pragma lifecycle(startup, update)
const HARD_HIT = 4; // metres per second
let body;let lastSpeed = 0;
// On a dynamic Crate with a Rigid Body, a Box Collider and a Signal Emitter with the signal 'crate'.// A disabled entity named 'Sparks' in the scene is the effect to copy.function startup() { body = self.parent.getComponent(PhysicsRigidBodyComponent);
on('crate', (event) => { if (event.entityId !== self.parent.entityId) return; if (event.eventType !== EventType.PhysicsCollider.CollisionEnter) return; if (lastSpeed < HARD_HIT || !event.data.contact) return;
const sparks = spawn('Sparks', { position: event.data.contact, enabled: true }); delay(() => destroy(sparks), 1000); });}
function update() { const v = body.linearVelocity(); lastSpeed = Math.hypot(v.x, v.y, v.z);}How it works
Section titled “How it works”The script is explained step by step in Sparks where something hits hard.
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.
ImpactSparks.xrproj