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.
For the example setup a primitive capsule will be used (GameObject menu > 3D Object > Capsule).
Ship
(add a new tag if it does not exist). The tag is only necessary so that the ship changer can find your ship.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.AdvancedShipController
component to the parent object (the one containing the Rigidbody
).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.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)
Rudder Transfrom
field under Rudders foldout. WaterObject
component to the rudder so it too can interact with water.Camera
of any type to the ship object (as a child) and tag it ShipCamera
.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.Apply Thrust When Above Water
is left unchecked).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.
Engine sound is achieved through simple pitch modulation. To set up sound:
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.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.