Break a weld on impact
Updated
A statue of three parts welded by a Fixed Joint stands as one object until a falling wrecking ball hits it faster than 6 m/s: the script then disables the joint and the parts fall apart.
Watch the ball drop onto the statue and break the weld. Press Relaunch to see it again. Drag to orbit the camera, scroll to zoom.
Break a weld on impact
#pragma lifecycle(startup, update)
const BREAK_SPEED = 6;
let weld;let ball;let ballSpeed = 0; // last frame's speed, before a hit slows itlet broken = false;
function startup() { weld = findEntity('Statue').getComponent(PhysicsFixedJointComponent); ball = findEntity('Wrecking Ball');
on('statue', (event) => { if (broken || event.eventType !== EventType.PhysicsCollider.CollisionEnter) return; if (event.data.otherEntityId !== ball.entityId || ballSpeed < BREAK_SPEED) return; broken = true; weld.setEnabled(false); log(`Hit at ${ballSpeed.toFixed(1)} m/s: the weld breaks`); emit('statue/broken'); });}
function update() { const v = ball.getComponent(PhysicsRigidBodyComponent).linearVelocity(); ballSpeed = Math.hypot(v.x, v.y, v.z);}How it works
Section titled “How it works”The script is explained step by step in Break a weld on impact.
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.
BreakableStatue.xrproj