NWH Vehicle Physics 2
Search Results for

    Show / Hide Table of Contents

    Class FuelModule

    Fuel system simulation module for NWH Vehicle Physics 2.

    Inheritance
    object
    VehicleComponent
    FuelModule
    Inherited Members
    VehicleComponent.state
    VehicleComponent.vehicleController
    VehicleComponent.IsActive
    VehicleComponent.VC_Initialize(VehicleController)
    VehicleComponent.VC_Initialize()
    VehicleComponent.VC_SetDefaults()
    VehicleComponent.VC_LoadStateFromStateSettings()
    VehicleComponent.VC_Update(float)
    VehicleComponent.VC_Disable(bool)
    VehicleComponent.VC_DrawGizmos()
    VehicleComponent.VC_Validate(VehicleController)
    VehicleComponent.UpdateLOD()
    VehicleComponent.ToggleState()
    Namespace: NWH.VehiclePhysics2.Modules.Fuel
    Assembly: NWH.VehiclePhysics2.dll
    Syntax
    [Serializable]
    public class FuelModule : VehicleComponent
    Remarks

    Simulates fuel consumption based on engine power output and efficiency. The module calculates realistic fuel consumption using the engine's current power generation, maximum power, and thermodynamic efficiency to determine fuel usage rates.

    Key features: - Physically-based consumption calculation using engine power and efficiency - Automatic engine shutdown when fuel is depleted - Real-time consumption metrics in various units (L/100km, MPG, L/h) - Idle consumption simulation for realistic stationary fuel usage - Configurable consumption multiplier for gameplay balancing

    The fuel consumption model assumes gasoline with approximately 36 MJ/L energy content. For other fuel types, adjust the efficiency and consumption multiplier accordingly. Diesel engines typically have 35-45% efficiency, while gasoline engines have 25-35% efficiency.

    Fields

    amount

    Current amount of fuel in the tank (liters).

    Declaration
    [Tooltip("Current amount of fuel in liters.")]
    public float amount
    Field Value
    Type Description
    float
    Remarks

    Can be modified at runtime to simulate refueling or fuel loss. Automatically clamped between 0 and capacity. When reaching 0, the engine will stop and cannot be restarted until fuel is added.

    capacity

    Maximum fuel tank capacity (liters).

    Declaration
    [Tooltip("Fuel capacity in liters.")]
    public float capacity
    Field Value
    Type Description
    float
    Remarks

    Typical values: - Motorcycles: 10-25 L - Compact cars: 35-50 L - Mid-size cars: 50-70 L - SUVs/Trucks: 70-120 L - Sports cars: 60-90 L

    consumptionMultiplier

    Multiplier for fuel consumption rate.

    Declaration
    [Tooltip("In case you do not need physically accurate fuel consumption you can lower/rise the consumption in here.")]
    public float consumptionMultiplier
    Field Value
    Type Description
    float
    Remarks

    Use this to balance gameplay without changing the physical model. Values less than 1.0 reduce consumption for arcade-style gameplay. Values greater than 1.0 increase consumption for more challenging resource management.

    0.5 = Half consumption (double range) 1.0 = Realistic consumption 2.0 = Double consumption (half range)

    efficiency

    Thermal efficiency of the engine (0-1 range).

    Declaration
    [Tooltip("Engine efficiency (in percent). 1 would mean that all the energy contained in fuel would go into output power.")]
    public float efficiency
    Field Value
    Type Description
    float
    Remarks

    Represents the percentage of fuel energy converted to mechanical work. Real engines lose energy to heat, friction, and exhaust.

    Typical values: - Gasoline engines: 0.25-0.35 (25-35% efficiency) - Diesel engines: 0.35-0.45 (35-45% efficiency) - High-performance racing engines: 0.35-0.40 - Hybrid systems: 0.40-0.50 (with energy recovery)

    Higher efficiency means lower fuel consumption for the same power output.

    idleConsumption

    Fuel consumption at idle as a fraction of maximum consumption.

    Declaration
    [Tooltip("Consumption when idling indicated in percentage of max consumption. 0.05f = 5% out of maximum.")]
    public float idleConsumption
    Field Value
    Type Description
    float
    Remarks

    Determines the minimum fuel consumption when the engine is running but not under load. This simulates the fuel needed to keep the engine running at idle RPM.

    Typical values: - Economy cars: 0.05-0.08 (5-8% of max) - Standard cars: 0.08-0.12 (8-12% of max) - Performance cars: 0.12-0.20 (12-20% of max) - Large displacement engines: 0.15-0.25 (15-25% of max)

    maxConsumptionPerHour

    Maximum theoretical fuel consumption rate in liters per hour.

    Declaration
    [NonSerialized]
    public float maxConsumptionPerHour
    Field Value
    Type Description
    float
    Remarks

    Calculated based on engine maximum power and efficiency. Represents fuel consumption when engine is at full power output. Used as the upper bound for consumption calculations.

    onOutOfFuel

    Unity event triggered when the fuel tank becomes empty.

    Declaration
    [Tooltip("Called when vehicle runs out of fuel.")]
    public UnityEvent onOutOfFuel
    Field Value
    Type Description
    UnityEvent
    Remarks

    Fired once when transitioning from having fuel to being empty. Use this to trigger warning sounds, UI notifications, or gameplay events. The engine will automatically stop when this event is triggered.

    Properties

    ConsumptionKilometersPerLiter

    Current fuel consumption in kilometers per liter.

    Declaration
    public float ConsumptionKilometersPerLiter { get; }
    Property Value
    Type Description
    float
    Remarks

    Higher values indicate better fuel economy. Updated in real-time based on current driving conditions. Returns 0 when stationary or engine is off.

    ConsumptionLitersPer100Kilometers

    Current fuel consumption in liters per 100 kilometers.

    Declaration
    public float ConsumptionLitersPer100Kilometers { get; }
    Property Value
    Type Description
    float
    Remarks

    Standard European fuel economy metric. Lower values indicate better fuel economy. Updated in real-time based on current driving conditions.

    ConsumptionLitersPerSecond

    Current fuel consumption rate in liters per second.

    Declaration
    public float ConsumptionLitersPerSecond { get; }
    Property Value
    Type Description
    float
    Remarks

    Instantaneous fuel flow rate. Useful for calculating remaining run time or for detailed consumption displays.

    ConsumptionMPG

    Current fuel consumption in miles per gallon (US).

    Declaration
    public float ConsumptionMPG { get; }
    Property Value
    Type Description
    float
    Remarks

    Standard US fuel economy metric. Higher values indicate better fuel economy. Updated in real-time based on current driving conditions.

    FuelPercentage

    Current fuel level as a percentage of tank capacity (0-1).

    Declaration
    public float FuelPercentage { get; }
    Property Value
    Type Description
    float
    Remarks

    Useful for fuel gauge displays. 0 = Empty tank 0.5 = Half full 1.0 = Full tank

    HasFuel

    Indicates whether the vehicle has fuel available for engine operation.

    Declaration
    public bool HasFuel { get; }
    Property Value
    Type Description
    bool
    Remarks

    Returns true if there is fuel in the tank or if the fuel module is disabled. When false, the engine cannot start or will stop if running.

    Methods

    VC_Enable(bool)

    Enables the fuel module and initializes tracking variables.

    Declaration
    public override bool VC_Enable(bool calledByParent)
    Parameters
    Type Name Description
    bool calledByParent

    True if called by parent component, false otherwise.

    Returns
    Type Description
    bool

    True if successfully enabled, false otherwise.

    Overrides
    VehicleComponent.VC_Enable(bool)
    Remarks

    Stores the initial fuel amount for change detection.

    VC_FixedUpdate(float)

    Updates fuel consumption calculations and depletes fuel based on engine operation.

    Declaration
    public override void VC_FixedUpdate(float DeltaTime)
    Parameters
    Type Name Description
    float DeltaTime

    Time since last fixed update in seconds.

    Overrides
    VehicleComponent.VC_FixedUpdate(float)
    Remarks

    This method is called every physics frame when the module is enabled. It performs the following operations:

    - Calculates maximum consumption based on engine power and efficiency - Determines current consumption from engine power output - Depletes fuel from tank based on consumption rate - Stops engine when fuel is depleted - Updates consumption metrics (L/100km, MPG, km/L) - Triggers onOutOfFuel event when transitioning to empty

    See Also

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