Dynamic Water Physics 2
Search Results for

    Show / Hide Table of Contents

    Ship Controller

    AdvancedShipController controls engines, rudders, bow and stern thrusters, stabilization, and the anchor for a vessel that already has a working Rigidbody and one or more WaterObject hulls.

    Ship input

    Add one ship input provider to the scene. The current ship-control names are:

    • Steering
    • Throttle, Throttle2, Throttle3, and Throttle4
    • BowThruster and SternThruster
    • SubmarineDepth
    • EngineStartStop
    • Anchor
    • RotateSail

    The Input System package is a declared dependency and the samples use InputSystemShipInputProvider. Legacy Input Manager projects can instead use InputManagerShipInputProvider with axes and buttons having the exact names above.

    Use these names exactly. For independent engine control, assign each Engine.throttleBinding to Throttle, Throttle2, Throttle3, or Throttle4.

    Adding a ship

    For a minimal test vessel, a capsule can be used in place of a finished hull.

    1. Create the hull GameObject and add a Rigidbody.
    2. Add WaterObjectWizard, run Auto-Setup, and review the generated WaterObject simulation mesh. See Quick Start for manual setup.
    3. Add AdvancedShipController to the same GameObject as the Rigidbody. Unity also adds its required Anchor component.
    4. Assign referenceWaterObject to the primary hull. If it is left empty, AdvancedShipController.Start() uses the first child WaterObject it finds.
    5. Configure the Rigidbody center of mass. A lower Y value usually improves roll stability, but placing it below the keel can make the vessel lean into turns. This uses the Rigidbody's own center-of-mass controls; no separate center-of-mass component is required.
    6. Add at least one engine and, when steering through water forces, a rudder.
    7. Add one input provider to the scene and enter Play mode.

    The Ship tag is not required by AdvancedShipController. If the scene uses NWH Common's optional VehicleChanger, add the ship to its vehicles list and add a matching scene input provider.

    Rudders

    Example rudder setup.

    1. Add a child transform for each rudder.
    2. Add an entry to AdvancedShipController.rudders.
    3. Assign its rudderTransform, then configure localRotationAxis, maxAngle, and rotationSpeed.
    4. Add a WaterObject to the rudder mesh if it should generate the actual steering force. The Rudder entry rotates the transform; it does not apply a steering force by itself.

    The current rudder input is ShipInputHandler.Steering.

    Engines

    Engine section of AdvancedShipController.

    Each entry in AdvancedShipController.engines is a propulsion system:

    1. Set thrustPosition in the ship's local space and set a non-zero thrustDirection.
    2. Set maxThrust, maxSpeed, and the desired throttleBinding.
    3. Optionally assign propellerTransform and audio sources.
    4. Enable applyThrustWhenAboveWater only when thrust should continue outside the water. Otherwise the controller applies thrust only while the thrust position is submerged.

    Engine thrust point and direction.

    Thrusters

    Thruster position and propulsion settings.

    Add entries to AdvancedShipController.thrusters, choose BowThruster or SternThruster for thrusterPosition, and configure position and maxThrust. The corresponding BowThruster or SternThruster input controls the entry.

    Engine sound

    Engine sound settings.

    For each engine:

    • Assign a looping source to runningSource.
    • Optionally assign startingSource and stoppingSource.
    • Set startDuration and stopDuration to match the useful part of their clips.
    • Tune pitch, pitchRange, volume, and volumeRange.

    Optional cameras

    Camera changing is provided by NWH Common rather than AdvancedShipController. Add a child CameraChanger, make its cameras children or populate its cameras list, and add a scene input provider if the feature is needed.

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