Drop traffic cones with Cone Colliders
Updated
Traffic cones tumble onto the ground and settle on their bases or roll on their sides, because each Cone Collider has the cone’s own shape, tip up. The script drops them again every few seconds.
Watch where the cones come to rest: upright, tipped over or rolling on their sides. Drag to orbit the camera, scroll to zoom.
Drop traffic cones with Cone Colliders
#pragma lifecycle(startup)
function wait(ms) { return new Promise((done) => delay(done, ms));}
const axis = new THREE.Vector3();
// 1 when the cone stands on its base, -1 on its tip.function tilt(cone) { return axis.set(0, 1, 0).applyQuaternion(cone.quaternion).y;}
async function startup() { const cones = []; for (let i = 1; i <= 7; i++) { const cone = findEntity(`Traffic Cone ${i}`); cones.push({ body: cone.getComponent(PhysicsRigidBodyComponent), home: cone.position.clone() }); } log('Dropping 7 cones with Cone Colliders'); for (;;) { await wait(5000); const upright = cones.filter(({ body }) => tilt(body.entity) > 0.95).length; log(`${upright} of 7 cones landed upright`); for (const { body, home } of cones) { const turn = new THREE.Quaternion().setFromEuler(new THREE.Euler(Random.range(0, M_TAU), Random.range(0, M_TAU), 0)); body.teleport(home, turn); body.wakeUp(); } }}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.
ConeDrop.xrproj