Tumble rocks with Convex Hull Colliders
Updated
Faceted rocks fall and tumble to rest on their flat faces: each Convex Hull Collider wraps its rock’s mesh, squashed or not, as tightly as a convex shape can. The script drops them again every few seconds.
Watch the rocks bounce off each other and settle on a face, never on a corner. Drag to orbit the camera, scroll to zoom.
Tumble rocks with Convex Hull Colliders
#pragma lifecycle(startup)
function wait(ms) { return new Promise((done) => delay(done, ms));}
async function startup() { const rocks = []; for (let i = 1; i <= 6; i++) { const rock = findEntity(`Rock ${i}`); rocks.push({ body: rock.getComponent(PhysicsRigidBodyComponent), home: rock.position.clone() }); } log('Each rock collides as the convex hull of its mesh'); for (let drop = 1; ; drop++) { await wait(6000); for (const { body, home } of rocks) { body.teleport(home, new THREE.Quaternion().setFromEuler(new THREE.Euler(Random.range(0, M_TAU), Random.range(0, M_TAU), 0))); body.applyTorqueImpulse({ x: Random.range(-0.3, 0.3), y: 0, z: Random.range(-0.3, 0.3) }); } log('Drop', drop + 1); }}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.
ConvexRocks.xrproj