User Tools


Ship Controller

Step-by-step Setup Guide for Ship Controller

Input

Before starting a few input bindings need to be set up for everything to work properly. These can be added under Edit ⇒ Project Settings ⇒ Input.
These are:

  • EngineStartStop (only positive button)
  • AnchorDropWeight (only positive button)
  • LeftThrottle (both positive and negative button)
  • RightThrottle (both positive and negative button)
  • SternThruster (both positive and negative button)
  • BowThruster (both positive and negative button)
  • SubmarineDepth (both positive and negative button)

If a function related to the input binding is not needed the binding can be skipped. E.g. if the submarine depth is not needed that input binding can be skipped.

Example input settings after adding the bindings.

Adding a Ship

For the example setup a primitive capsule will be used (GameObject menu > 3D Object > Capsule).

Capsule representing a ship.
  1. Add the ship object into the scene and tag it Ship (add a new tag if it does not exist). The tag is only necessary so that the ship changer can find your ship.
  2. Add WaterObjectWizard component to the ship object. Tick the particle system option and click on Auto-Setup button. Click play - the object will float now. For manual WaterObject setup folow the guide here.
  3. Add AdvancedShipController component to the parent object (the one containing the Rigidbody).
  4. Add CenterOfMass component to the parent object and adjust center of mass to be near the bottom of the ship (green sphere). If this is not done the ship will most likely tilt to the side since the center of mass in Unity is calculated as a center of volume of all of the Rigidbody colliders, which is unrealistic for ships which generally have the center of mass near the keel.
  5. Add the following Axes under Edit ⇒ Project Settings ⇒ Input if they do not already exist.
    • EngineStartStop (only positive button)
    • AnchorDropWeight (only positive button)
    • SubmarineDepth (both positive and negative button)
    • LeftThrottle (both positive and negative button)
    • RightThrottle (both positive and negative button)
    • SternThruster (both positive and negative button)
    • BowThruster (both positive and negative button)

Rudders

As an example a simple primitive cube will be used.



  1. Add a rudder (in this case just a scaled cube) to the ship.
  2. Assign the rudder transform (in this example the scaled cube) to the Rudder Transfrom field under Rudders foldout.
  3. Add WaterObject component to the rudder so it too can interact with water.
  4. Add a Camera of any type to the ship object (as a child) and tag it ShipCamera.
  5. Press play and cycle to your ship using the V button (default change ship button). The boat is now floating and the rudders turn. If the rudders turn around wrong axis the rotation of the model needs to be fixed. Check this link for a guide on how to fix the model rotation.

Engines

Engine section of AdvancedShipController.
  1. To make ship move an engine and propeller are needed. Ship Controller assumes that there is one propeller per engine. Add an engine under Engines tab and set the wanted values (hover over each value to see what it does). If thrust position is above the water thrust will not be applied (if Apply Thrust When Above Water is left unchecked).
An example engine setup with thrust point shown as red sphere and thrust direction as a red line.

Thrusters

An example thruster with thrust point showin as a sphere and thrust direction as a blue line.

Larger ships usually have bow and/or stern thrusters to help them maneuver. Thruster is indicated as a blue sphere with a a line indicating direction of thrust when positive input is pressed.

Sound

Sound section of AdvancedShipController

Engine sound is achieved through simple pitch modulation. To set up sound:

  • Add an AudioSource to the ship object and assign a looped engine sound clip to it. Drag the AudioSource to the field Running Source under Engine foldout.
  • Same should be done for Starting Source and Stopping Source fields. These fields are options. Adjust the Start Duration and Stop Duration fields to be somewhat shorter than the length of starting and stopping clips.