Raise a storm over the sea
Updated
One tween changes wave height, foam and rain together on four ocean tiles, turning a calm sea into a storm and back.
Press Storm to raise the waves over twelve seconds, and Calm to let them settle. Drag to orbit the camera, scroll to zoom.
Raise a storm over the sea
#pragma lifecycle(startup)
const TILES = ['Ocean Tile 1', 'Ocean Tile 2', 'Ocean Tile 3', 'Ocean Tile 4'];const CALM = { waveHeight: 0.3, foam: 0.4, rain: 0 };const STORM = { waveHeight: 2.2, foam: 0.9, rain: 0.8 };
let seas = [];let current = { ...CALM };let tween = null;
function applyWeather(from, to, t) { current = { waveHeight: from.waveHeight + (to.waveHeight - from.waveHeight) * t, foam: from.foam + (to.foam - from.foam) * t, rain: from.rain + (to.rain - from.rain) * t, }; for (const sea of seas) sea.setProps(current);}
function changeWeather(to, seconds) { if (tween) tween.stop(); const from = { ...current }; tween = Tween.value(0, 1, (t) => applyWeather(from, to, t), { duration: seconds, ease: Ease.InOutSine });}
function startup() { seas = TILES.map((name) => findEntity(name)).filter(Boolean).map((tile) => tile.getComponent(WaterMeshComponent)); applyWeather(CALM, CALM, 1);
on('weather/storm', () => changeWeather(STORM, 12)); on('weather/calm', () => changeWeather(CALM, 20));}How it works
Section titled “How it works”The script is explained step by step in Raise a storm over the sea.
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.
SeaStorm.xrproj