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
| Member | Description |
|---|---|
| Fluid2D.Enabled | Whether this component is enabled. Use SetEnabled to change it. |
| Fluid2D.ParticleCount | Number of live particles after the latest physics publication. |
| Fluid2D.Compression | Mean positive relative density error; excludes free-surface deficits. |
| Fluid2D.PeakCompression | Maximum positive relative density error in the latest microstep. |
| Fluid2D.EmittedRate | Accepted births in the latest fixed tick divided by tick duration, in particles per second. |
| Fluid2D.DrainedRate | Removed particles in the latest fixed tick divided by tick duration, in particles per second. |
Methods
| Member | Description |
|---|---|
| Fluid2D.Clear | Remove all live liquid from this domain; waits until the domain is ready if called before physics setup. |
| Fluid2D.Reset | Restore the authored initial fill and clear emission carry and diagnostics. |
| Fluid2D.SetEnabled | Enable or disable the domain. Disabling disposes live particles; re-enabling starts a fresh authored fill. |
| Fluid2D.SamplePoint | Sample 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);
}
}