Fog that rolls in
Updated
An avenue of columns under a hazy sky: Fog closes in over four seconds when you press Fog and pulls back when you press Clear, with near and far tweened together on the scene root’s Fog.
Press Fog and watch the far columns fade into the mist, then press Clear. Drag to orbit the camera, scroll to zoom.
Fog that rolls in
#pragma lifecycle(startup)
const CLEAR = { near: 40, far: 300 };const FOGGY = { near: 2, far: 25 };let fog;let tween = null;
function moveFog(to) { if (tween) tween.stop(); const from = { near: fog.props.near, far: fog.props.far }; tween = Tween.value(0, 1, (t) => { // Both edges in one call, so near always stays below far. fog.setProps({ near: from.near + (to.near - from.near) * t, far: from.far + (to.far - from.far) * t, }); }, { duration: 4, ease: Ease.InOutSine });}
function startup() { fog = scene.findEntity(scene.rootId).getComponent(FogComponent); fog.setProps({ mode: 'linear', color: '#b8c4cc', ...CLEAR });
on('weather/fog', () => moveFog(FOGGY)); on('weather/clear', () => moveFog(CLEAR));}How it works
Section titled “How it works”The script is explained step by step in Fog that rolls in.
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.
RollingFog.xrproj