Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commit3bb1da2647

README.md

Water

Still water in a box, placed as an entity and saved with its scene: a pool, a pond, a tank, a moat, a flooded room, a canal with a current. Its surface is the box's top face and its floor the box's bottom face; the box is world-aligned, size metres along each axis, centred on the entity, and follows the entity as it moves. Physics.water(point) answers from it like every other body of water (Physics.waters() lists it), and every body carrying FluidForces floats in it, is dragged by it and is carried by its current. Physics.onWater hears a body or a character going into it and coming out (a splash, a swim state), and Physics.immersion(id) reads how much of one stands in it. It draws nothing itself: put the water's surface mesh or material where its top face stands.

Public fields:

  • size (m, default {10, 2, 10}): the box the water fills.
  • current (m/s, world frame, default {0, 0, 0}): how the whole body moves, a river's or a canal's flow.
  • density (kg/m³, default 1000): 1000 for fresh water, 1025 for the sea.
  • priority (default 2): where bodies of water overlap the higher answers; a sea defines 0, a terrain's lakes 1, so a pool on a beach answers inside its box.

Disabling the component drains it. A sea of waves is the Ocean component's, and a landscape's lakes and rivers a Terrain's; Physics.defineWater defines any of the three kinds from a script.

-- a pond 18 m by 14 m and 3 m deep: its surface stands 1.5 m above the entity
pond.component.add("Water", { size = { 18, 3, 14 } })

-- a canal running east at 1.5 m/s
canal.component.add("Water", { size = { 200, 3, 8 }, current = { 1.5, 0, 0 } })