A stepped day cycle
Updated
A Day Sky with the runtime Sky & Terrain demo’s golden-hour clouds runs from sunrise to sunset in four minutes, stepped once a second, with the Sun light re-aimed and dimmed to match.
Watch the sun climb and the light on the shapes change; a whole day takes four minutes. Drag to orbit the camera, scroll to zoom.
A stepped day cycle
#pragma lifecycle(startup, update)
const DAY_SECONDS = 240; // sunrise to sunsetconst STEP = 1; // update the sky once a second, not every frame
let sky;let sun;let sunLight;let elapsed = 0;let wait = 0;
function apply() { sky.setProps({ time: (elapsed / DAY_SECONDS) % 1 }); sun.lookAt(sun.position.clone().add(sky.sunDirection)); sunLight.setProps({ intensity: 0.3 + Math.max(0, sky.sunDirection.y) * 2.2 });}
function startup() { sky = scene.findEntity(scene.rootId).getComponent(DaySkyComponent); sun = findEntity('Sun'); sunLight = sun.getComponent(DirectionalLightComponent); apply();}
function update(dt) { elapsed += dt; wait -= dt; if (wait > 0) return; wait = STEP; apply();}How it works
Section titled “How it works”The script is explained step by step in A stepped day cycle.
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.
DayCycle.xrproj