Dynamic Water Physics 2
Search Results for

    Show / Hide Table of Contents

    Quick Start

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

    Sample Prerequisites

    Before starting with NWH Dynamic Water Physics 2, import the required samples:

    Important

    NWH Common Package > Common Base Sample must be imported first. This sample is required for all NWH package samples to function properly.

    Samples are imported via Package Manager > In Project > NWH Dynamic Water Physics 2 > Samples.

    Note

    Samples are found in the Package Manager under the "In Project" category in the left sidebar, NOT under "My Assets" or other categories.

    The Base Sample contains the main demo scene and is required before importing other Dynamic Water Physics samples (Multiplayer, water integration samples).

    Water Object

    Warning: If making an open-world game with a large-scale map (> ~4000 units), the floating origin is required (not only for this asset, but in general with game engines that use floating point precision). See floating origin explanation.

    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 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 the 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 have a linear performance penalty with minimal quality gain. For the example sphere, 36 is sufficient.
    Example Auto Setup
    1. Add a 3D Object > Sphere to the scene.
    2. Attach WaterObjectWizard to the sphere and press Auto-Setup.

    Center Of Mass

    Center of Mass is one of the most important settings for a ship. A ship with too high center of mass will capsize. Center of Mass can be adjusted by unticking the automatic center of mass on the Rigidbody and adjusting the values there. Lower Y value will make the ship more resistant to capsizing, but setting it below the keel will make the ship lean into the corner instead of away from it.

    Water Data Provider

    WaterDataProvider is a script that tells WaterObject where the water is. It is an interface between water systems/assets and DWP2. 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. The WaterDataProvider can be added to any GameObject in the scene. Multiple water surfaces can be used in the same scene 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
    • FlatWaterDataProvider can be used to make water height follow a flat primitive plane.
    • For more info and 3rd party asset integration check the Water Assets page.

    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 above the water and press play. The 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.

    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 manual setup section above.

    1. Add a 3D Object > Sphere to the scene.
    2. Add WaterObjectWizard to the newly created 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.
    • Edit this page
    In this article
    Back to top Copyright © NWH - Vehicle Physics, Aerodynamics, Dynamic Water Physics