0 votes
by
retagged by
I noticed there is fuel consumption, is there any way for me to set the fuel tank value?

1 Answer

0 votes
by
edited by
 
Best answer

You may read the instant fuel consumption from the Data Bus, then accumulate it over time and/or subtract it from a given start value.

// Available fuel in grams (g): 10 Kg
float availableFuel = 10000.0f;

// Get instant fuel consumption rate in grams per second (g/s)
float instantFuelConsumption = vehicle.data.Get(Channel.Vehicle, VehicleData.EngineFuelRate) / 1000.0f;

// Account for the fuel consumed this frame
availableFuel -= instantFuelConsumption * Time.deltaTime;

// Ensure the engine can run only when fuel is available.
Engine engine = vehicle.GetInternalObject(typeof(Engine)) as Engine;
if (availableFuel > 0.0f)
    engine.allowedFuelRatio = 1.0f;
else
    engine.allowedFuelRatio = 0.0f;

Configuring the fuel consumption in the engine is documented in this answer:

https://support.vehiclephysics.com/80/how-to-simulate-fuel-consumption

Note: accessing the Engine block is not available in the Community Edition. Here GetInternalObject always return null.

by
Hi Edy, can you give me an updated script on how to access the engine allowedFuelRatio? i keep getting error when accessing the Engine block.
Thank you.

P.S.  I have a professional license.
by
Please write to the support email for questions related to the Professional Edition. Thank you!
...