Dig and raise the ground under the pointer
Updated
Holding R, F or G sculpts the terrain under the mouse every frame with sculptAt, raising, lowering or smoothing it; releasing the key commits the change.
Point at the ground and hold R to raise it, F to lower it or G to smooth it. Drag to orbit the camera, scroll to zoom.
Dig and raise the ground under the pointer
#pragma lifecycle(startup, update)
const RADIUS = 3;let ground;let terrain;let working = false;
const BRUSHES = { [Key.R]: { tool: 'raise', strength: 0.5, falloff: 'smooth' }, [Key.F]: { tool: 'lower', strength: 0.5, falloff: 'smooth' }, [Key.G]: { tool: 'smooth', strength: 0.8 },};
function startup() { ground = findEntity('Terrain'); terrain = ground.getComponent(TerrainComponent);}
function activeBrush() { for (const key of [Key.R, Key.F, Key.G]) { if (Input.keyboard.isKeyPressed(key)) return BRUSHES[key]; } return null;}
function update(dt) { const brush = activeBrush();
if (!brush) { if (working) { terrain.commit(); working = false; } return; }
const hit = GraphicsRaycaster.fromScreen(Input.mouse.position()).hit(ground); if (!hit) return;
terrain.sculptAt(hit.point, RADIUS, brush, dt); working = true;}How it works
Section titled “How it works”The script is explained step by step in Dig and raise the ground under the pointer.
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.
TerraformTool.xrproj