Dynamic Water Physics 2
Search Results for

    Show / Hide Table of Contents

    Water Object

    WaterObject inspector

    WaterObject is the main script of DWP2. It handles all the buoyancy and hydrodynamics calculations.

    WaterObject gets the data needed for simulation from the Simulation Mesh. This is a static mesh that will be used for simulating water/object interaction and can either be the original mesh or a simplified version of it. WaterObject provides basic tools for mesh triangle decimation, removal of co-located vertices, and convexification - if needed.

    WaterObject with WaterObjectManager's Debug field enabled

    Tips

    • When using hollow boat/ship hulls it is recommended to use the Convex option when generating the simplified mesh.
    • WaterObject density should be above ~15kg/m. Large volume, extremely low mass objects can cause the object to jump/fly away when falling into the water. Use MassFromVolume script to calculate mass from object volume / density.

    Field Explanations

    Force Coefficients

    • buoyantForceCoefficient - Multiplier for buoyancy forces. Increase to make the object float higher, decrease to make it sink deeper.
    • hydrodynamicForceCoefficient - Multiplier for all hydrodynamic forces (pressure drag). Affects how much the water resists object movement.
    • skinDragCoefficient - Multiplier for friction drag as water flows over the surface. Higher values increase surface drag.
    • slamForceCoefficient - Multiplier for impact forces when faces enter the water. Higher values create more splash and resistance.
    • suctionForceCoefficient - Multiplier for forces when faces exit the water. Higher values increase the suction effect.

    Simulation Settings

    • fluidDensity - Density of the fluid in kg/m³. Default is 1030 (seawater). Use 1000 for fresh water.
    • targetTriangleCount - Number of triangles in the simplified simulation mesh. Lower values improve performance but reduce accuracy. Range: 8-256.
    • velocityDotPower - Exponent applied to the velocity-normal dot product. Higher values reduce hydrodynamic forces when triangles are nearly parallel to water flow.

    Mesh Processing

    • simplifyMesh - Reduces triangle count of the simulation mesh to targetTriangleCount for better performance.
    • convexifyMesh - Makes the simulation mesh convex. Useful for hollow hulls or partially open meshes.
    • weldColocatedVertices - Merges vertices at the same position. Improves performance and is recommended.

    Public Methods

    • GetWaterHeightSingle(Vector3 point) - Returns water height at a single point in world space. Uses the current WaterDataProvider or falls back to defaultWaterHeight if none is active.
    • IsTouchingWater() - Returns true if any part of the object is touching water (at least one triangle is submerged). Cache the result if calling this frequently to avoid iterating through all triangle states each frame.
    • StartSimMeshPreview() - Enables visualization of the simulation mesh in the scene view by temporarily replacing the MeshFilter's mesh. Useful for inspecting mesh simplification results.
    • StopSimMeshPreview() - Disables simulation mesh preview and restores the original mesh to the MeshFilter.
    • GenerateSimMesh() - Generates or regenerates the simulation mesh based on current settings (simplifyMesh, convexifyMesh, weldColocatedVertices, targetTriangleCount). Call this after changing any mesh processing settings.

    Instantiating at Run-time

    WaterObjects can be instantiated at run-time like any other GameObject.

    • Edit this page
    In this article
    Back to top Copyright © NWH - Vehicle Physics, Aerodynamics, Dynamic Water Physics