Dynamic Water Physics 2
Search Results for

    Show / Hide Table of Contents

    Submarine

    Submarine inspector.

    Submarine adds variable ballast and optional leveling to an AdvancedShipController. The current implementation changes the same GameObject's Rigidbody.mass and Rigidbody.centerOfMass directly. It does not require VariableCenterOfMass.

    Submarine requires AdvancedShipController and Rigidbody components on the same GameObject.

    Fields and properties

    • ballastChangeSpeed controls ballast change per second as a proportion of maxBallastMass.
    • maxBallastMass is the maximum added ballast in kilograms.
    • keepHorizontal enables center-of-mass shifting for automatic leveling.
    • keepHorizontalSensitivity controls the leveling response.
    • maxMassOffset limits the leveling offset applied to the Rigidbody center of mass.
    • DepthInput accepts -1 for surfacing through +1 for diving.
    • BallastMass reports the currently added ballast.
    • TotalMass reports base Rigidbody mass plus current ballast.

    The component caches the Rigidbody's starting mass and center of mass in Start. Ballast is clamped between zero and maxBallastMass.

    Setup

    1. Configure a working vessel with Rigidbody, WaterObject, and AdvancedShipController.
    2. Add Submarine to the same GameObject as the Rigidbody and AdvancedShipController.
    3. Set maxBallastMass and ballastChangeSpeed.
    4. Optionally enable keepHorizontal, then tune keepHorizontalSensitivity and maxMassOffset.
    5. Set up the SubmarineDepth action through a ship input provider. The shipped Input System bindings use K for surface (-1) and I for dive (+1).

    When AdvancedShipController.input.autoSetInput is enabled, Submarine reads the combined SubmarineDepth() value from all scene ShipInputProvider components. When automatic input is disabled, set Submarine.DepthInput from code.

    Upgrading from product release 14.1

    Product release 14.2 changed ShipInputStates.submarineDepth to the complete -1 to +1 range. This product release number is separate from the UPM package version described in the changelog.

    For a custom UI wired through MobileShipInputProvider.submarineDepthSlider, set the slider's minValue to -1. The shipped keyboard and Input System bindings already provide both directions.

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