codeAPI Reference
s&box WaterVolume: Water buoyancy
WaterVolume Component API Reference
WaterVolume is a Component that applies buoyancy physics to rigidbodies entering a water volume. Implements ITriggerListener for detection. Automatically added to colliders tagged "water" by GameManager.
Type Signature
CSHARP
public class WaterVolume : Component, Component.ITriggerListener
{
List<Rigidbody> Bodies = new();
}Behavior
In OnFixedUpdate:
- Calculates water surface from BoxCollider (top of the volume)
- Creates a water plane at the surface
- Applies buoyancy to all tracked rigidbodies using Rigidbody.ApplyBuoyancy()
ITriggerListener Implementation
- OnTriggerEnter(Collider other) - Adds Rigidbody from entering GameObject to tracking list
- OnTriggerExit(Collider other) - Removes Rigidbody from tracking list
GameManager Integration
GameManager.AfterLoad automatically adds WaterVolume to all colliders tagged "water" in the scene.
Usage
CSHARP
// Tag a collider as "water" to enable buoyancy
collider.Tags.Add("water");
// GameManager will automatically add WaterVolume componentNotes
- Uses BoxCollider to determine water surface (top of volume)
- Tracks rigidbodies entering/leaving the volume
- Applies buoyancy each fixed update
- Automatically added by GameManager on scene load
- Water surface is calculated as WorldPosition + Up (Scale.z 0.5)
Was this helpful?