User Tools

Quick Start

This quick start guide will explain how to set up a primitive sphere to interact with water.
An empty scene will be used for the example.

Water Object Manager

WaterObjectManager is the main script of Dynamic Water Physics 2 and has to be present in the scene for water/object interaction to work. It does not matter to which object it is attached, it just needs to be present. WaterObjectManager fetches the data from all the WaterObjects in the scene, processes it and sends it to a job which then does all the physics calculations and makes use of multiple CPU cores.

  1. Add a WaterObjectManager to the scene. No need to change any settings. Example:
Example WaterObjectManager setup.

Water Object

WaterObject is a script that tells WaterObjectManager which objects should interact with water. Any object that is active and has this script will interact with water. There are two requirements for WaterObject to work: a Rigidbody and a MeshFilter from which the script will fetch the mesh (DWP2 uses mesh data to simulate object/water interaction). Rigidbody does not have to be attached to the same object as WaterObject, but it must be present in one of its parents. This allows for composite objects; one Rigidbody with multiple hulls - such as a trimaran.

  1. Add a 3D Object ⇒ Sphere to the scene.
  2. Add a Sphere Collider to the Sphere if is not automatically added.
  3. Add a Rigidbody to the Sphere and set its mass to 300. There is also a script called MassFromMaterial which can calculate and set the Rigidbody mass based on material density and mesh volume, but it is a helper script and not required.
  4. Add WaterObject to the Sphere. Since the sphere by default has 768 triangles Simplify Mesh option should be used. This option automatically decimates the mesh to a Target Triangle Count. A good triangle count is 30 or less for simple objects and around 60 for ship hulls. Using higher triangle count will only have a minor influence on simulation quality but will have a linear performance penalty (doubling the triangle count will about halve the performance). Therefore, adjusting the triangle count until the object starts to lose its shape is recommended. In the case of the example sphere 36 will be enough:
Example WaterObject setup.

Water Data Provider

WaterDataProvider is a script that tells WaterObjectManager where the water is. It is an interface between water systems/assets and Dynamic Water Physics and allows the two to communicate. All flat water assets/shaders use the same WaterDataProvider: FlatWaterDataProvider while for wavy assets such as Crest an asset-specific WaterDataProvider has to be used, e.g. CrestWaterDataProvider.
As an example a flat water plane will be used:

  1. Create an empty object using RMB ⇒ Create Empty and name it Water. Name does not matter.
  2. Add FlatWaterDataProvider to it and press Play. The object will now float but it will appear as if it floating in empty space (which it is). FlatWaterDataProvider assumes that water is at transform.position.y of the object it is attached to and does not care about any shaders, colliders, etc. Changing the Y value of Transform's position will make the Sphere float at different heights.
  3. To make this look more realistic, a plane can be added instead. Delete the Water object created in step 1 and create a 3D Object plane instead. Attach FlatWaterDataProvider and make sure to remove MeshCollider from it or the sphere will just sit on the plane through physics collision.
  4. Press play again. The sphere floats the same as in step 2 but it appears it is in 'water'. At this point Default-Material of the plane can be replaced with a material that uses some kind of flat water shader - e.g. the included WaterProDaytime material which is just a standard Unity water.
A result of following this guide. Not pretty, but fully functional.

Water Particle System

WaterParticleSystem can be used to generate foam. It works with any flat water.

  1. Drag DefaultWaterParticleSystem from DWP2 ⇒ Resources into the scene and parent it to the Sphere.
    Example WaterParticleSystem setup.
  2. Move the Sphere to be above the water and press play. Sphere falling into the water will generate foam around it based on simulation data. WaterParticleSystem and ParticleSystem values can be tweaked to suit the needs of the project.

Center Of Mass

CenterOfMass is a simple script that offsets the center of mass of a Rigidbody.
Unity calculates center of mass of the object from all of its colliders, as if the object were homogenous. In many cases this is not correct - a ship has ballast, a crate could have some load in it, a barrel could have oil, etc.
To adjust the center of mass of an object simply attach CenterOfMass script to the same object that contains the Rigidbody and adjust the Center Of Mass Offset - a value in local coordinates which tells how much to offset center of mass from the Unity-calculated point. Want a ship to be less prone to capsizing? Lower the Y component of COM.

CenterOfMass inspector.

Water Object Wizard

WaterObjectWizard is a helper script that sets up a WaterObject automatically. It is still recommended to have knowledge of manual setup and how things work, but this script can automate and speed up the setup process.
A primitive Sphere will be used, same as in the rest of the guide above.

  1. Add a 3D Object > Sphere to the scene.
  2. Add WaterObjectWizard to the newly create Sphere.
  3. Tick Add Water Particle System (optional). This option is self-explanatory.
  4. Click Auto-Setup and press Play after the setup is done. The Sphere now floats and generates foam. Next step would be to manually check and tweak the default values, such as Target Triangle Count, center of mass, etc.

Enabling Burst

Burst is a compiler, it translates from IL/.NET bytecode to highly optimized native code using LLVM. This improves job performance.
It can be installed from Unity PackageManager.
By default Burst compilation is disabled. This is due to the fact that cross compilation is not supported in some cases. E.g. building for Mac OS on Windows will fail if Burst is enabled.

To enable Burst compilation add DWP_BURST under Project Settings ⇒ Player ⇒ Scripting Define Symbols. Make sure that the Burst package installed beforehand.