Tidal 2 URP
Scripting Reference

Water Queries & API

Runtime scripting reference for v2.2.0 - namespace Tidal.Core.

All runtime API calls run on the main thread in Play mode. Queries read a GPU-baked copy of the surface, so height and normal samples match the rendered water. The examples below belong inside a MonoBehaviour with using Tidal.Core;, using UnityEngine; and using System.Collections.Generic;.

Always check for a valid water sample

GetWaterHeight returns float.MinValue outside a bounded body, in a clipped volume, or before the simulation is ready. Check h > float.MinValue before using the height, or use TryGetWaterSurface and check its boolean result. With multiple bodies, resolve the body at the query position first.

Finding water

TidalWaterBody.FindBodyAt(position)

TidalWaterBody.AllBodies

TidalManager.Instance.TryGetCameraWaterInfo(camera, out body, out waterY)

Resolve the water body that covers a world position, enumerate active bodies, or ask the manager for the water at a camera.

void FindingTheWater()
{
    // The body whose water covers a point (null when no body does).
    TidalWaterBody body = TidalWaterBody.FindBodyAt(transform.position);

    // Every active body in the loaded scenes.
    foreach (TidalWaterBody b in TidalWaterBody.AllBodies)
        Debug.Log(b.name);

    // Which body a camera is in, and the water height at the camera.
    if (TidalManager.Instance != null &&
        TidalManager.Instance.TryGetCameraWaterInfo(Camera.main, out TidalWaterBody camBody,
                                                    out float waterY))
    {
        bool cameraUnderwater = Camera.main.transform.position.y < waterY;
    }
}

TidalWaterBody water queries

float GetWaterHeight(Vector3 position)

bool TryGetWaterSurface(Vector3 position, out float height, out Vector3 normal)

body.GetWaterNormal(position, ignoreVolumes, sampleDist)

Vector2 GetWaterFlow(Vector3 position)

float GetSubmersion01(Vector3 position, float radius)

Query height, normal, current and submersion on the selected body. Height is world Y; flow is world XZ in metres per second. Pass your hull volumes to ignore them when sampling.

void ReadingTheSurface(TidalWaterBody body)
{
    Vector3 p = transform.position;

    // Surface height (world Y). float.MinValue = no water here (outside a lake's
    // bounds, a clipped volume, or the simulation not ready yet) - always check it.
    float h = body.GetWaterHeight(p);
    if (h > float.MinValue)
    {
        bool under = p.y < h;
        float depth = h - p.y;                  // > 0 when the point is underwater
    }

    // Height and normal in one call; false where there is no water.
    if (body.TryGetWaterSurface(p, out float height, out Vector3 normal))
    {
        transform.up = normal;
    }

    // Surface normal on its own (ignore a list of volumes, sample spacing in metres).
    Vector3 n = body.GetWaterNormal(p, null, 0.5f);

    // The current: world XZ, metres per second (zones, whirlpools, propellers).
    Vector2 flow = body.GetWaterFlow(p);
    Vector3 flow3 = new Vector3(flow.x, 0f, flow.y);

    // How much of a sphere is under the water, 0..1.
    float submerged = body.GetSubmersion01(p, 0.5f);

    // Ignore volumes that carve water out of your own hull.
    List<TidalVolume> myHull = new List<TidalVolume>();
    float hIgnoringHull = body.GetWaterHeight(p, myHull);
}

Breaking waves and water columns

bool TryGetWaterColumn(Vector3 position, out TidalWaterColumn column)

bool TryGetWaterSurfaceBelow(Vector3 position, out float height, out Vector3 normal)

GetWaterHeight returns the top surface. Under a breaking curl, use the water column to distinguish the water from the air pocket and inspect the surfaces above and below the point.

void UnderACurl(TidalWaterBody body)
{
    Vector3 p = transform.position;

    // GetWaterHeight reports the TOP surface - under a barrel that is the lip above you.
    // The column reports every surface on the line.
    if (body.TryGetWaterColumn(p, out TidalWaterColumn col))
    {
        bool inWater   = col.Submerged;           // in water (not in the air pocket)
        float signed   = col.Depth;               // + under water, - in air
        float top      = col.TopSurface;
        int surfaces   = col.SurfaceCount;        // > 1 = the wave folds over here
        bool overhang  = col.Overhang;
        if (col.HasSurfaceBelow) { float below = col.SurfaceBelow; Vector3 nb = col.NormalBelow; }
        if (col.HasSurfaceAbove) { float above = col.SurfaceAbove; Vector3 na = col.NormalAbove; }
        if (col.HasWaterVelocity) { Vector3 v = col.WaterVelocity; }   // the wave's water
    }

    // Shortcut: the nearest surface at or below the point (the face under a barrel).
    if (body.TryGetWaterSurfaceBelow(p, out float floorY, out Vector3 floorN)) { }
}

TidalBuoyancy

TidalBuoyancy.IsInWater

TidalBuoyancy.FloatPoints

TidalBuoyancy.IgnoreVolumes

Attach buoyancy to a Rigidbody, place float points around the hull, and set the force per point for the mass. Ignore the hull volume and its own wake when needed.

void MakeItFloat(GameObject boat, TidalWaterBody body)
{
    var rb = boat.GetComponent<Rigidbody>();
    var buoy = boat.AddComponent<TidalBuoyancy>();
    buoy.ConnectedRigid = rb;
    buoy.UsingTidalBody = body;                          // null = first body found

    // Float points: 4+ children at the hull's bottom corners (more = better pitch/roll).
    buoy.FloatPoints = new Transform[4];
    Vector3[] corners = { new Vector3(-1, -0.5f, -2), new Vector3(1, -0.5f, -2),
                          new Vector3(-1, -0.5f,  2), new Vector3(1, -0.5f,  2) };
    for (int i = 0; i < 4; i++)
    {
        var fp = new GameObject("Float Point " + i).transform;
        fp.SetParent(boat.transform, false);
        fp.localPosition = corners[i];
        buoy.FloatPoints[i] = fp;
    }

    // BuoyancyFactor is a FORCE per point (x 9.81 N), not scaled by mass:
    // about mass / points x 2 rides half submerged.
    buoy.BuoyancyFactor = rb.mass / buoy.FloatPoints.Length * 2f;

    buoy.CenterOfMassOffset = new Vector3(0f, -0.5f, 0f);   // lower = harder to capsize
    buoy.FlowFollow = 1f;          // drift at the current's speed (0 = still-water drag)
    buoy.KeelEffect = 0.7f;        // boats: resist sliding sideways (0 for crates)
    buoy.IgnoreOwnWake = true;     // don't sink into the hull's own wake dimple
    buoy.RideUnderCurls = false;   // true: float on the face under a breaking curl
    buoy.IgnoreVolumes = new List<TidalVolume>();   // e.g. the hull's own Exclude volume

    bool afloat = buoy.IsInWater;
}

Propulsion (BETA), wakes and foam

TidalPropulsion.Throttle

TidalPropulsion.PushRigidbody

TidalPropulsion.Thrust

TidalPropulsion.Submersion

TidalPropulsion is BETA in v2.2; its settings and behaviour may change. Place it at the stern with the Z axis pointing forward. Throttle drives the jet, and PushRigidbody optionally applies thrust to the boat. Emitters follow their GameObject automatically.

void BoatEffects(GameObject boat, float throttleInput)
{
    // Propeller / jet: pushes water backwards, churns foam and a wake.
    // Put it at the stern, Z axis pointing forward.
    var prop = boat.GetComponentInChildren<TidalPropulsion>();
    prop.Throttle = throttleInput;          // -1..1, drive it from your controller
    prop.PushRigidbody = false;             // true = it also moves the boat itself
    float thrust = prop.Thrust;             // newtons actually applied
    float inWater = prop.Submersion;        // 0..1

    // A wake trail (displaces the water) and a foam-only trail. Size and strength are
    // set in the Inspector; the emitters follow their GameObject on their own.
    boat.AddComponent<TidalWakeEmitter>();
    boat.AddComponent<TidalFoamEmitter>();
}

Impacts and body settings

body.AddImpact(position, radius, depth, duration, foamSeconds)

body.WakeModel = TidalWakeModel.Fast

body.WaveStrength = 0.33f

AddImpact makes a one-off crater that releases ring waves. Radius and depth are metres, duration and foam lifetime are seconds, and depth is capped at 40 m. WaveStrength is per body even when several bodies share one simulation.

void Impacts(TidalWaterBody body, Vector3 hitPoint)
{
    // A crater pushed into the water then released: rings that rock floating objects.
    // radius (m) ~ wavelength, depth (m) ~ height (max 40), duration (s), foam (s).
    body.AddImpact(hitPoint, 6f, 3f, 0.4f, 4f);

    // Wake physics: Realistic (deep-water Kelvin wake) or Fast (cheaper cone).
    body.WakeModel = TidalWakeModel.Fast;

    // How big this body's waves are, 0..1 - also on a simulation shared with others.
    body.WaveStrength = 0.33f;
}

TidalWaveBox

TidalWaveBox.Play()

TidalWaveBox.Pause()

TidalWaveBox.Stop()

TidalWaveBox.Playhead

TidalWaveBox.InAirPocket(position)

Single Wave mode supports playback controls and a normalised playhead. Consecutive mode runs an endless set. A steepness product above 1 produces an overturning curl.

void WaveBoxes(TidalWaveBox box)
{
    box.Mode = TidalWaveBoxMode.SingleWave;   // or Consecutive (endless set)

    box.Play();                // start (Single Wave: one wave crosses the box)
    box.Pause();               // hold where it is
    box.Stop();                // back to the start, flat
    box.Playhead = 0.5f;       // jump to a point along the wave's run, 0..1
    bool rolling = box.IsPlaying;
    float seconds = box.Duration;

    // Is it steep enough to curl? Q*k*A above 1 overturns into a barrel.
    bool curls = box.SteepnessProduct > 1f;
    bool lipOk = box.LipWithinWavelength;   // lip does not reach the next wave
    float breakAt = box.BreakPoint;          // < 1 = breaks inside the box

    // Inside the wave? (0 = outside, 1 = fully inside)
    float w = box.WeightAtXZ(new Vector2(transform.position.x, transform.position.z));
    bool inBarrelAir = box.InAirPocket(transform.position);
    bool cameraInBarrel = TidalWaveBox.ViewerInAirPocket;
}

TidalWhirlpool

TidalWhirlpool.Radius

TidalWhirlpool.FunnelDepthMetres

TidalWhirlpool.FlowStrength

Tune whirlpools in the Inspector. These runtime properties are read-only; funnel depth is metres and FlowStrength is the peak current speed in metres per second.

void Whirlpools(TidalWhirlpool pool)
{
    float radius     = pool.Radius;              // influence radius (m)
    float eye        = pool.CoreRadius;
    float funnel     = pool.FunnelDepthMetres;    // how deep the pit is
    float peakFlow   = pool.FlowStrength;         // peak current speed (m/s)
    bool clockwise   = pool.Clockwise;
}

Volumes and body scope

TidalVolumeAnalytic.AnalyticType

TidalVolume.Flags

TidalVolume.ClipVisual

volume.Affects(body)

Exclude water from a hull, include it inside a pool, or damp waves in a shape. A non-empty AffectedBodies list is exclusive: only those bodies are affected, and the layer mask is ignored.

void Volumes(GameObject hull, TidalWaterBody body)
{
    var vol = hull.AddComponent<TidalVolumeAnalytic>();
    vol.AnalyticType = TidalVolumeAnalyticTypes.Cube;   // size = the transform's scale
    vol.Flags = TidalVolumeFlags.EXCLUDE;               // INCLUDE, DAMPEN, NONE
    vol.Damping = 0.25f;                                // DAMPEN only: 1 = untouched
    vol.ClipVisual = TidalClipVisuals.CROSS_SECTION;    // show the water column on cuts

    // Scoping: a NON-EMPTY list is exclusive - only these bodies are affected.
    vol.AffectedBodies = new List<TidalWaterBody> { body };
    bool hits = vol.Affects(body);
}

TidalZone

zone.IsInside(position)

zone.SampleFlowWorld(position)

zone.SampleHeightWorld(position, out height)

zone.SampleDampingWorld(position, out damping)

zone.MarkTextureDirty()

Sample a painted zone at a world position. After editing the texture pixels from script, call MarkTextureDirty so the water updates the baked zone map.

void Zones(TidalZone zone)
{
    Vector3 p = transform.position;
    if (zone.IsInside(p))
    {
        Vector2 current = zone.SampleFlowWorld(p);                       // Flow zones
        if (zone.SampleHeightWorld(p, out float extraHeight)) { }        // Height zones
        if (zone.SampleDampingWorld(p, out float calm)) { }              // Damping zones
        float raw = zone.Sample01(p, 1f);
    }

    // After changing the zone texture's pixels from script:
    zone.MarkTextureDirty();
}

Wave simulation and mesh settings

TidalMeshSharedSettings GetTidalMeshSettings()

TidalGerstnerCompute.ActiveGerstnerProfile

TidalFFTCompute.ActiveTidalProfile

Use GetTidalMeshSettings to assign the wave simulation, viewer camera or tessellation. Assign a Gerstner profile before switching TCompute. Windows Standalone is the supported build target; mobile is untested.

void Simulation(TidalWaterBody body, TidalProfileGerstner gerstnerProfile)
{
    TidalMeshSharedSettings settings = body.GetTidalMeshSettings();

    // Switch a body to Gerstner waves (lower-cost alternative; mobile is untested).
    var gerstner = body.gameObject.AddComponent<TidalGerstnerCompute>();
    gerstner.ActiveGerstnerProfile = gerstnerProfile;   // Assets > Create > Tidal 2 > Water Profile (Gerstner)
    gerstner.Size = ComputeTidalSize.W256;             // 256-512 for Gerstner
    settings.TCompute = gerstner;

    // Or the FFT ocean: swap its profile at runtime.
    var fft = body.GetComponent<TidalFFTCompute>();
    if (fft != null) { TidalProfile current = fft.ActiveTidalProfile; }

    // Per body, on the mesh settings.
    settings.Tessellation = true;            // smooth curls / whirlpools (GPU cost)
    settings.ViewerCam = Camera.main;        // the camera the water is built around
    float maxWave = settings.MaxWaveHeightEstimate;
}

Key return values

CallReturns
GetWaterHeight(p)World Y of the top surface; float.MinValue = no water (outside a lake, clipped, not ready)
TryGetWaterSurface(p, out h, out n)false where there is no water
GetWaterFlow(p)Current as world XZ in m/s (zones, whirlpools, propellers)
GetSubmersion01(p, r)Fraction of a sphere of radius r under water
TryGetWaterColumn(p, out col)Every surface on the vertical line - use under breaking curls
TryGetWaterSurfaceBelow(p, ...)Nearest surface at or below p (the face under a barrel)
AddImpact(pos, radius, depth, duration, foamSeconds)Ring waves; depth max 40 m

Complete example

Download Tidal2ApiExamples.cs for the complete example class.