Class Engine
Represents a ship engine and propeller system that generates thrust. Simulates RPM-based thrust generation with start/stop sequences and sound effects. Includes propeller efficiency modeling through thrust curves and support for reverse thrust. Multiple engines can be used per ship for differential thrust control.
Namespace: NWH.DWP2.ShipController
Assembly: NWH.DWP2.dll
Syntax
[RequireComponent(typeof(AdvancedShipController))]
[Serializable]
public class Engine
Fields
| Edit this page View SourceapplyThrustWhenAboveWater
Should thrust be applied when above water?
Declaration
[Tooltip("Should thrust be applied when above water?")]
public bool applyThrustWhenAboveWater
Field Value
| Type | Description |
|---|---|
| bool |
isOn
Is the engine currently on?
Declaration
[FormerlySerializedAs("_isOn")]
[Tooltip("Is the engine currently on?")]
public bool isOn
Field Value
| Type | Description |
|---|---|
| bool |
maxRPM
Max RPM of the engine.
Declaration
[FormerlySerializedAs("_maxRPM")]
[Tooltip("Max RPM of the engine.")]
public float maxRPM
Field Value
| Type | Description |
|---|---|
| float |
maxSpeed
Ship speed in m/s at which the propeller thrust drops to zero due to water flow matching propeller speed. Used with thrustCurve to determine thrust efficiency at different ship speeds.
Declaration
[Tooltip("Ship speed at which propeller will reach its maximum rotational speed.")]
public float maxSpeed
Field Value
| Type | Description |
|---|---|
| float |
maxThrust
Thrust at max RPM.
Declaration
[FormerlySerializedAs("_maxThrust")]
[Tooltip("Thrust at max RPM.")]
public float maxThrust
Field Value
| Type | Description |
|---|---|
| float |
minRPM
Min RPM of the engine.
Declaration
[FormerlySerializedAs("_minRPM")]
[Tooltip("Min RPM of the engine.")]
public float minRPM
Field Value
| Type | Description |
|---|---|
| float |
name
Display name for this engine.
Declaration
public string name
Field Value
| Type | Description |
|---|---|
| string |
pitch
Idle pitch of the engine
Declaration
[Range(0, 2)]
[Tooltip("Idle pitch of the engine")]
public float pitch
Field Value
| Type | Description |
|---|---|
| float |
pitchRange
Pitch range of the engine.
Declaration
[Tooltip("Pitch range of the engine.")]
[Range(0, 2)]
public float pitchRange
Field Value
| Type | Description |
|---|---|
| float |
propellerRpmRatio
Engine RPM will be multiplied by this value to get rotation speed of the propeller. Animation only.
Declaration
[Tooltip("Engine RPM will be multiplied by this value to get rotation speed of the propeller. Animation only.")]
public float propellerRpmRatio
Field Value
| Type | Description |
|---|---|
| float |
propellerTransform
Optional. Propeller transform. Visual rotation only, does not affect physics.
Declaration
[Tooltip("Optional. Propeller transform. Visual rotation only, does not affect physics.")]
public Transform propellerTransform
Field Value
| Type | Description |
|---|---|
| Transform |
reverseThrustCoefficient
Amount of thrust that will be applied if ship is reversing
Declaration
[Tooltip("Amount of thrust that will be applied if ship is reversing")]
public float reverseThrustCoefficient
Field Value
| Type | Description |
|---|---|
| float |
rotationDirection
Direction of propeller rotation. Affects animation only.
Declaration
[Tooltip("Direction of propeller rotation. Affects animation only.")]
public Engine.RotationDirection rotationDirection
Field Value
| Type | Description |
|---|---|
| Engine.RotationDirection |
rudderTransform
Optional. Only use if you vessel has propeller mounted to the rudder (as in outboard engines). Propuslion force direction will be rotated with rudder if assigned.
Declaration
[Tooltip("Optional. Only use if you vessel has propeller mounted to the rudder (as in outboard engines). Propuslion force direction will be rotated with rudder if assigned.")]
public Transform rudderTransform
Field Value
| Type | Description |
|---|---|
| Transform |
runningSource
Engine running audio source.
Declaration
[Tooltip("Engine running audio source.")]
public AudioSource runningSource
Field Value
| Type | Description |
|---|---|
| AudioSource |
spinUpTime
Time needed to spin up the engines up to max RPM
Declaration
[FormerlySerializedAs("_spinUpTime")]
[Tooltip("Time needed to spin up the engines up to max RPM")]
public float spinUpTime
Field Value
| Type | Description |
|---|---|
| float |
startDuration
How long the engine starting phase take?
Declaration
[Tooltip("How long the engine starting phase take?")]
public float startDuration
Field Value
| Type | Description |
|---|---|
| float |
startOnThrottle
Should the engine start when the throttle is applied?
Declaration
[Tooltip("Should the engine start when the throttle is applied?")]
public bool startOnThrottle
Field Value
| Type | Description |
|---|---|
| bool |
startingRPM
Engine RPM when turning over. Used to determine starting sound pitch.
Declaration
[FormerlySerializedAs("startingRpm")]
[Tooltip("Engine RPM when turning over. Used to determine starting sound pitch.")]
public float startingRPM
Field Value
| Type | Description |
|---|---|
| float |
startingSource
Engine starting source.
Declaration
[Tooltip("Engine starting source.")]
public AudioSource startingSource
Field Value
| Type | Description |
|---|---|
| AudioSource |
stopDuration
How long will the engine stopping phase take?
Declaration
[Tooltip("How long will the engine stopping phase take?")]
public float stopDuration
Field Value
| Type | Description |
|---|---|
| float |
stoppingSource
Engine stopping source.
Declaration
[Tooltip("Engine stopping source.")]
public AudioSource stoppingSource
Field Value
| Type | Description |
|---|---|
| AudioSource |
throttleBinding
Which throttle input this engine responds to.
Declaration
public Engine.ThrottleBinding throttleBinding
Field Value
| Type | Description |
|---|---|
| Engine.ThrottleBinding |
thrustCurve
Thrust curve of the propeller. X axis is speed in m/s and y axis is efficiency.
Declaration
[Tooltip("Thrust curve of the propeller. X axis is speed in m/s and y axis is efficiency.")]
public AnimationCurve thrustCurve
Field Value
| Type | Description |
|---|---|
| AnimationCurve |
thrustDirection
Local direction in which the force will be applied. Does not affect the rotation of the propeller, which always happens around the local Z-axis of the propeller transform.
Declaration
[Tooltip("Local direction in which the force will be applied. Does not affect the rotation of the propeller, which always happens around the local Z-axis of the propeller transform.")]
public Vector3 thrustDirection
Field Value
| Type | Description |
|---|---|
| Vector3 |
thrustPosition
Local position where the thust is applied, relative to ship.
Declaration
[Tooltip("Local position where the thust is applied, relative to ship.")]
public Vector3 thrustPosition
Field Value
| Type | Description |
|---|---|
| Vector3 |
volume
Base volume of the engine
Declaration
[Range(0, 2)]
[Tooltip("Base volume of the engine")]
public float volume
Field Value
| Type | Description |
|---|---|
| float |
volumeRange
Volume range of the engine.
Declaration
[Tooltip("Volume range of the engine.")]
[Range(0, 2)]
public float volumeRange
Field Value
| Type | Description |
|---|---|
| float |
Properties
| Edit this page View SourceEngineState
Current state of the engine (On, Off, Starting, or Stopping).
Declaration
public Engine.State EngineState { get; set; }
Property Value
| Type | Description |
|---|---|
| Engine.State |
IsInitialized
Returns true if the engine has been initialized with a parent ship controller.
Declaration
public bool IsInitialized { get; }
Property Value
| Type | Description |
|---|---|
| bool |
RPM
Current RPM of the engine
Declaration
public float RPM { get; }
Property Value
| Type | Description |
|---|---|
| float |
RpmPercent
Current RPM as a normalized value between 0 (minRPM) and 1 (maxRPM). Used for sound pitch and volume calculations.
Declaration
public float RpmPercent { get; }
Property Value
| Type | Description |
|---|---|
| float |
Submerged
True if the engine's thrust position is currently underwater. When false, the engine will not generate thrust unless applyThrustWhenAboveWater is enabled.
Declaration
public bool Submerged { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Thrust
Current thrust being generated by the engine and propeller in Newtons.
Declaration
public float Thrust { get; }
Property Value
| Type | Description |
|---|---|
| float |
ThrustDirection
Direction of thrust force in world coordinates.
Declaration
public Vector3 ThrustDirection { get; }
Property Value
| Type | Description |
|---|---|
| Vector3 |
ThrustPosition
Point at which thrust will be applied to the Rigidbody, in world coordinates.
Declaration
public Vector3 ThrustPosition { get; }
Property Value
| Type | Description |
|---|---|
| Vector3 |
Methods
| Edit this page View SourceInitialize(AdvancedShipController)
Initializes the engine with a reference to its parent ship controller.
Declaration
public void Initialize(AdvancedShipController sc)
Parameters
| Type | Name | Description |
|---|---|---|
| AdvancedShipController | sc | The ship controller this engine belongs to. |
SetDefaults()
Sets all engine parameters to default values suitable for most ships.
Declaration
public void SetDefaults()
SoundInit()
Initializes engine sound sources.
Declaration
public virtual void SoundInit()
SoundUpdate()
Updates engine sound pitch and volume based on RPM and state.
Declaration
public virtual void SoundUpdate()
StartEngine()
Starts the ship engine.
Declaration
public void StartEngine()
StopEngine()
Stops the ship engine.
Declaration
public void StopEngine()
Update()
Declaration
public virtual void Update()