Dynamic Water Physics 2
Search Results for

    Show / Hide Table of Contents

    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.

    Inheritance
    object
    Engine
    Namespace: NWH.DWP2.ShipController
    Assembly: NWH.DWP2.dll
    Syntax
    [RequireComponent(typeof(AdvancedShipController))]
    [Serializable]
    public class Engine

    Fields

    | Edit this page View Source

    applyThrustWhenAboveWater

    Should thrust be applied when above water?

    Declaration
    [Tooltip("Should thrust be applied when above water?")]
    public bool applyThrustWhenAboveWater
    Field Value
    Type Description
    bool
    | Edit this page View Source

    isOn

    Is the engine currently on?

    Declaration
    [FormerlySerializedAs("_isOn")]
    [Tooltip("Is the engine currently on?")]
    public bool isOn
    Field Value
    Type Description
    bool
    | Edit this page View Source

    maxRPM

    Max RPM of the engine.

    Declaration
    [FormerlySerializedAs("_maxRPM")]
    [Tooltip("Max RPM of the engine.")]
    public float maxRPM
    Field Value
    Type Description
    float
    | Edit this page View Source

    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
    | Edit this page View Source

    maxThrust

    Thrust at max RPM.

    Declaration
    [FormerlySerializedAs("_maxThrust")]
    [Tooltip("Thrust at max RPM.")]
    public float maxThrust
    Field Value
    Type Description
    float
    | Edit this page View Source

    minRPM

    Min RPM of the engine.

    Declaration
    [FormerlySerializedAs("_minRPM")]
    [Tooltip("Min RPM of the engine.")]
    public float minRPM
    Field Value
    Type Description
    float
    | Edit this page View Source

    name

    Display name for this engine.

    Declaration
    public string name
    Field Value
    Type Description
    string
    | Edit this page View Source

    pitch

    Idle pitch of the engine

    Declaration
    [Range(0, 2)]
    [Tooltip("Idle pitch of the engine")]
    public float pitch
    Field Value
    Type Description
    float
    | Edit this page View Source

    pitchRange

    Pitch range of the engine.

    Declaration
    [Tooltip("Pitch range of the engine.")]
    [Range(0, 2)]
    public float pitchRange
    Field Value
    Type Description
    float
    | Edit this page View Source

    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
    | Edit this page View Source

    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
    | Edit this page View Source

    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
    | Edit this page View Source

    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
    | Edit this page View Source

    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
    | Edit this page View Source

    runningSource

    Engine running audio source.

    Declaration
    [Tooltip("Engine running audio source.")]
    public AudioSource runningSource
    Field Value
    Type Description
    AudioSource
    | Edit this page View Source

    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
    | Edit this page View Source

    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
    | Edit this page View Source

    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
    | Edit this page View Source

    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
    | Edit this page View Source

    startingSource

    Engine starting source.

    Declaration
    [Tooltip("Engine starting source.")]
    public AudioSource startingSource
    Field Value
    Type Description
    AudioSource
    | Edit this page View Source

    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
    | Edit this page View Source

    stoppingSource

    Engine stopping source.

    Declaration
    [Tooltip("Engine stopping source.")]
    public AudioSource stoppingSource
    Field Value
    Type Description
    AudioSource
    | Edit this page View Source

    throttleBinding

    Which throttle input this engine responds to.

    Declaration
    public Engine.ThrottleBinding throttleBinding
    Field Value
    Type Description
    Engine.ThrottleBinding
    | Edit this page View Source

    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
    | Edit this page View Source

    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
    | Edit this page View Source

    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
    | Edit this page View Source

    volume

    Base volume of the engine

    Declaration
    [Range(0, 2)]
    [Tooltip("Base volume of the engine")]
    public float volume
    Field Value
    Type Description
    float
    | Edit this page View Source

    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 Source

    EngineState

    Current state of the engine (On, Off, Starting, or Stopping).

    Declaration
    public Engine.State EngineState { get; set; }
    Property Value
    Type Description
    Engine.State
    | Edit this page View Source

    IsInitialized

    Returns true if the engine has been initialized with a parent ship controller.

    Declaration
    public bool IsInitialized { get; }
    Property Value
    Type Description
    bool
    | Edit this page View Source

    RPM

    Current RPM of the engine

    Declaration
    public float RPM { get; }
    Property Value
    Type Description
    float
    | Edit this page View Source

    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
    | Edit this page View Source

    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
    | Edit this page View Source

    Thrust

    Current thrust being generated by the engine and propeller in Newtons.

    Declaration
    public float Thrust { get; }
    Property Value
    Type Description
    float
    | Edit this page View Source

    ThrustDirection

    Direction of thrust force in world coordinates.

    Declaration
    public Vector3 ThrustDirection { get; }
    Property Value
    Type Description
    Vector3
    | Edit this page View Source

    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 Source

    Initialize(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.

    | Edit this page View Source

    SetDefaults()

    Sets all engine parameters to default values suitable for most ships.

    Declaration
    public void SetDefaults()
    | Edit this page View Source

    SoundInit()

    Initializes engine sound sources.

    Declaration
    public virtual void SoundInit()
    | Edit this page View Source

    SoundUpdate()

    Updates engine sound pitch and volume based on RPM and state.

    Declaration
    public virtual void SoundUpdate()
    | Edit this page View Source

    StartEngine()

    Starts the ship engine.

    Declaration
    public void StartEngine()
    | Edit this page View Source

    StopEngine()

    Stops the ship engine.

    Declaration
    public void StopEngine()
    | Edit this page View Source

    Update()

    Declaration
    public virtual void Update()
    • Edit this page
    • View Source
    In this article
    Back to top Copyright © NWH - Vehicle Physics, Aerodynamics, Dynamic Water Physics