[Physics] How to calculate car engine acceleration and deceleration

accelerationheat-enginesimulationsspeed

I'm trying to program some kind of car game in unity just for practice. So I want to start off with an engine that behaves normally, so I can then convert the engine's RPM into torque.

Currently, I have capped the engine's max rpm with a variable $maxRpm$.

I have added a second variable $acceleration$ because I don't really know how to have an accurate engine's acceleration (I'm not talking about the car's acceleration here but simply the rate at which the engine's rpm increases).

So to calculate the engine's RPM, at each physics update I take my $rpm$ variable and add to it the input of the gas pedal (between 0.0 and 1.0) times the acceleration times the elapsed time between two updates.

$$rpm = rpm + (gas \times acceleration \times deltaTime)$$

And now I'm wondering how to make the engine's speed decrease when the gas pedal is fully released, I've tried to find formulas concerning engine braking but didn't find anything, anyone as a clue?

Best Answer

I don't know whether there are any general formulas concerning engine braking, but you could incorporate drag proportional to the car's velocity:

$$ F =ma= -bv $$

where $b$ is a constant and $v$ the car's velocity. This should reproduce a similar effect to engine braking. The deceleration $a$ is then also proportional to the car's velocity:

$$ a = -\frac{bv}{m} $$

with $m$ the car's mass.


Edit:

Real drag due to aerodynamics is usually taken to be proportional to $v^2$, and also the (frontal) surface area of the car:

$$ F\sim\rho A v^2 $$

where $\rho$ is the density of the medium (in this case: air). I think that the model proportional to $v$ would emulate engine braking slightly better, but you can try both and see which feels more natural.

Related Question