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.

Assembly Definitions

Since all the NWH assets have been updated to use assembly definitions here is a disclaimer to avoid confusion when updating:

This asset uses Assembly Definition (.asmdef) files. There are many benefits to assembly definitions but a downside is that the whole project needs to use them or they should not be used at all.

  • If the project already uses assembly definitions accessing a script that belongs to this asset can be done by adding an reference to the assembly definition of the script that needs to reference the asset. E.g. to access AdvancedShipController adding a NWH.DWP2 reference to MyProject.asmdef is required.
  • If the project does not use assembly definitions simply remove all the .asmdef files from the asset after import.

Using, for example, Lux Water (which does not fature assembly definitions) will therefore require an addition of .asmdef file inside the Lux Water directory and a reference inside NWH.DWP2.asmdef or removal of all .asmdef files from the asset if you do not wish to use assembly definitions. Some assets such as Crest already feature .asmdefs and adding Crest as a reference to NWH.DWP2 is the only step needed.

Water Object Manager

WaterObjectManager has been removed in v2.5. All the settings and simulation is now handled by the WaterObject

Water Object

Any physics object that is active and has WaterObject attached will interact with water. There are two requirements for WaterObject to work: a Rigidbody and a MeshFilter:

  • MeshFilter is required so that the WaterObject knows which mesh to use for simulation.
  • 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.
Example Manual Setup
  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 Auto Setup
  1. Add a 3D Object โ‡’ Sphere to the scene.
  2. Attach WaterObjectWizard to the sphere and press Auto-Setup.
Example WaterObject setup.

Water Data Provider

WaterDataProvider is a script that tells WaterObject where the water is.
It is an interface between water systems/assets and DWP2 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 of version v2.5 an option to use multiple water surfaces in the same scene has been added. This is done by attaching a Collider with isTrigger = true to the WaterDataProvider. As long as the object is inside the trigger it will use data from that WaterDataProvider.

Minimal Setup
  1. Add a Cube (or any other mesh) to the scene.
  2. Attach WaterObject to the Cube. Make sure that a Rigidbody has been added.
  3. Press Play. The object will now float at default water height (set under WaterObject settings).
Adding Water

To add water to the scene check the Water Assets page.
FlatWaterDataProvider can be used to make water height follow a flat primitive plane which results in something like this:

A basic primitive plane used as water.

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.