codeAPI Reference

s&box WaterVolume: Buoyancy physics for water volumes

calendar_today May 12, 2026 schedule ~1 min read person patrickjr verified 50

WaterVolume API Reference

WaterVolume is a Component that applies buoyancy physics to Rigidbody objects entering a trigger volume.

Type Signature

CSHARP
public partial class WaterVolume : Component, Component.ITriggerListener

Physics Implementation

CSHARP
protected override void OnFixedUpdate()
{
    var collider = GetComponent<BoxCollider>();
    var waterSurface = WorldPosition + Vector3.Up * (collider.Scale.z * 0.5f);
    var waterPlane = new Plane(waterSurface, Vector3.Up);
    
    foreach (var body in Bodies)
    {
        body.ApplyBuoyancy(waterPlane, Time.Delta);
    }
}

ITriggerListener Implementation

Automatic Setup

GameManager automatically attaches WaterVolume to any collider tagged "water" after scene load:

CSHARP
void ISceneLoadingEvents.AfterLoad(Scene scene)
{
    var waterVolumes = scene.GetAll<Collider>().Where(x => x.Tags.Has("water"));
    foreach (var volume in waterVolumes)
    {
        volume.GetOrAddComponent<WaterVolume>();
    }
}

Notes

  • Uses Rigidbody.ApplyBuoyancy(Plane, float) for physics simulation.
  • Water surface is calculated from the BoxCollider's top face (Scale.z * 0.5).
  • Invalid Rigidbodies are automatically removed from the tracking list.
  • Tag your collider with "water" to enable automatic WaterVolume attachment.
Was this helpful?