Skip to content

Fluid2D ​

class in OpalScript

Experimental particle liquid. Emitters sharing this domain interact. Solid colliders contain the water; the object's rectangle is only its starting fill.

Properties ​

MemberDescription
Fluid2D.EnabledWhether this component is enabled. Use SetEnabled to change it.
Fluid2D.ParticleCountNumber of live particles after the latest physics publication.
Fluid2D.CompressionMean positive relative density error; excludes free-surface deficits.
Fluid2D.PeakCompressionMaximum positive relative density error in the latest microstep.
Fluid2D.EmittedRateAccepted births in the latest fixed tick divided by tick duration, in particles per second.
Fluid2D.DrainedRateRemoved particles in the latest fixed tick divided by tick duration, in particles per second.

Methods ​

MemberDescription
Fluid2D.ClearRemove all live liquid from this domain; waits until the domain is ready if called before physics setup.
Fluid2D.ResetRestore the authored initial fill and clear emission carry and diagnostics.
Fluid2D.SetEnabledEnable or disable the domain. Disabling disposes live particles; re-enabling starts a fresh authored fill.
Fluid2D.SamplePointSample committed water occupancy and flow at a world point. Coverage is approximate; returns a dry snapshot outside live liquid.

Example ​

csharp
class WaterReader : Component {
    public Entity water;
    void FixedUpdate(float dt) {
        if (water == null) return;
        Fluid2D domain = water.GetComponent<Fluid2D>();
        if (domain == null) return;
        Vector2 samplePosition = Transform.WorldPosition;
        RigidBody2D body = GetComponent<RigidBody2D>();
        if (body != null) samplePosition = body.SimulationPosition;
        FluidSample sample = domain.SamplePoint(samplePosition);
        if (sample.Present) Debug.Log(sample.VelocityY);
    }
}

See also ​