Class FuelModule
Fuel tank and consumption. Burn rate comes from generated engine power over efficiency, floored at the idle fraction, and stops the engine when the tank hits zero.
Inherited Members
Namespace: NWH.VehiclePhysics2.Modules.Fuel
Assembly: NWH.VehiclePhysics2.dll
Syntax
[Serializable]
public class FuelModule : VehicleComponent
Remarks
Energy content is fixed at 36 MJ/L (gasoline). Other fuels are covered by adjusting efficiency and consumptionMultiplier.
Fields
amount
Fuel in the tank, in liters. Writable at runtime for refueling, clamped to 0..capacity. At 0 the engine stops and will not restart until fuel is added.
Declaration
[Tooltip("Current amount of fuel in liters.")]
public float amount
Field Value
| Type | Description |
|---|---|
| float |
capacity
Tank capacity in liters.
Declaration
[Tooltip("Fuel capacity in liters.")]
public float capacity
Field Value
| Type | Description |
|---|---|
| float |
consumptionMultiplier
Scales the computed burn rate. 1 is the physical model; below 1 stretches range, above 1 shortens it.
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 |
efficiency
Fraction of fuel energy that becomes mechanical work, 0 to 1. Gasoline sits near 0.25-0.35, diesel near 0.35-0.45. Higher efficiency burns less for the same power.
Declaration
[Tooltip("Engine efficiency as a 0 to 1 fraction. 1 would mean that all the energy contained in fuel would go into output power.")]
public float efficiency
Field Value
| Type | Description |
|---|---|
| float |
idleConsumption
Floor on consumption while the engine runs unloaded, as a fraction of maxConsumptionPerHour. 0.05 is 5%.
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 |
maxConsumptionPerHour
Consumption in L/h at full engine power, derived from engine maxPower and efficiency. The idle floor is a fraction of this.
Declaration
[NonSerialized]
public float maxConsumptionPerHour
Field Value
| Type | Description |
|---|---|
| float |
onOutOfFuel
Fired once on the transition from having fuel to empty. The engine is already stopped by then.
Declaration
[Tooltip("Called when vehicle runs out of fuel.")]
public UnityEvent onOutOfFuel
Field Value
| Type | Description |
|---|---|
| UnityEvent |
Properties
ConsumptionKilometersPerLiter
Consumption in km/L. 0 when stationary or with the engine off.
Declaration
public float ConsumptionKilometersPerLiter { get; }
Property Value
| Type | Description |
|---|---|
| float |
ConsumptionLitersPer100Kilometers
Consumption in L/100km.
Declaration
public float ConsumptionLitersPer100Kilometers { get; }
Property Value
| Type | Description |
|---|---|
| float |
ConsumptionLitersPerSecond
Instantaneous fuel flow in L/s.
Declaration
public float ConsumptionLitersPerSecond { get; }
Property Value
| Type | Description |
|---|---|
| float |
ConsumptionMPG
Consumption in miles per imperial gallon, matching UnitConverter.L100kmToMpg. Not US MPG.
Declaration
public float ConsumptionMPG { get; }
Property Value
| Type | Description |
|---|---|
| float |
FuelPercentage
Tank level as a 0 to 1 fraction of capacity.
Declaration
public float FuelPercentage { get; }
Property Value
| Type | Description |
|---|---|
| float |
HasFuel
True when the tank has fuel, or when the module is inactive. While false the engine cannot start and stops if running.
Declaration
public bool HasFuel { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Methods
VC_Disable(bool)
Disables the component and stops its updates.
Declaration
public override bool VC_Disable(bool calledByParent)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | calledByParent | True when called by a parent ManagerVehicleComponent fan-out or the VehicleController enable/disable loop. The LOD system passes false. |
Returns
| Type | Description |
|---|---|
| bool | True if successfully disabled, false otherwise |
Overrides
Remarks
Refused on a component that is not initialized. Records whether the call came from a parent, which is what VC_Enable checks before a bulk re-enable.
VC_Enable(bool)
Installs the FuelAvailable engine run modifier and seeds the empty-tank edge detector.
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
VC_FixedUpdate(float)
Burns fuel for this step, refreshes the consumption readouts, and stops the engine and fires onOutOfFuel when the tank empties.
Declaration
public override void VC_FixedUpdate(float DeltaTime)
Parameters
| Type | Name | Description |
|---|---|---|
| float | DeltaTime | Time since last fixed update in seconds. |