User Tools

Quick Start

In this quick start we will get a capsule to float. You can use any other object as long as it has a MeshFilter component.

A WaterObject with Generate Debug Gizmos enabled.

Manual Setup

For demonstration purposes a primitive sphere will be used (GameObject > 3D Object > Capsule).   

  • Add ​WaterObject ​component to the object.

  • In case the object does not have a Rigidbody attached, or there are some other setup issues, WaterObject will throw a warning.

  • By default Rigidbody has a mass of 1 which is way too light for the capsule of this size. Set the Rigidbody mass to 300.
  • As an alternative to manually setting the mass of the object, a component RigidbodyMassFromChildren can be added to the Rigidbody object which will enable Material Settings section on the WaterObject. Here you can choose a Material Preset or manually set either Density or Mass (volume will be auto-calculated from the mesh). If one Rigidbody has multiple WaterObject children the mass of that Rigidbody will be calculated as a sum of all child WaterObject masses.

  • Add WaterObjectManager to any component in the scene, e.g. SceneManager. Exactly one WaterObjectManager needs to be present in the scene. It is responsible for all the physics calculations and the objects will not float without it.
Water Object Manager inspector. The behavior of WaterObjects can be adjusted here.
  • Press Play.
  • The capsule will fall on its side. This is because its center of mass is in the center. To make it stay upright attach CenterOfMass component to its Rigidbody and set Center Of Mass Offset to (0, -0.5, 0). Green sphere indicates current center of mass. This is important because ships have very low center of mass allowing them to stay upright and Unity calculates center of mass as a center of volume of the collider(s).

Automatic Setup

There is a quicker way to setup a Water Object than the one above. It is just a good idea to know how to set it up manually first.

  • Attach WaterObjectWizard to the object(s) that should float.
WaterObjectWizard inspector.
  • Tick Add Water Particle System if you want to add WaterParticleSystem (2D only).
  • Press Auto-Setup button. The object should now float.