Drop a shelf item on a signal
Updated
Items hung on a pegboard are fixed scenery with only a Box Collider; on shelf/shake, the script adds a dynamic Rigid Body to each one, and they fall.
Press Shake the shelf to make every item fall. Drag to orbit the camera, scroll to zoom.
Drop a shelf item on a signal
#pragma lifecycle(startup)
// Put this Behavior on the Shelf group. Each child of the shelf is a mesh with a Box Collider.let items = [];
function startup() { items = self.parent.children.filter((child) => isEntity(child) && child !== self);
on('shelf/shake', () => { for (const item of items) { if (item.getComponent(PhysicsRigidBodyComponent)) continue; item.addComponent(new PhysicsRigidBodyComponent({ type: 'dynamic', mass: 2 })); } log(`${items.length} items fall`); });}How it works
Section titled “How it works”The script is explained step by step in Drop a shelf item on a signal.
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.
ShelfShake.xrproj