concerning attempts to create home made car simulators are welcome here.
I am just starting out on such a project, and I want to make sure I have
the basics clear in my head. I hope that if you have any time then any
experts reading this might be able to scan my post and correct the
mistakes I am likely to be making at this stage. I have been reading
about this purely from the point of view of someone trying to write a
simulation and previously knew very little about the internals of a car.
I'm a C++ programmer, so please forgive me if my description of the
simulator components sounds a little unnaturally partitioned compared to
the way things sit in a car or if I lump together important components -
I'm probably just allowing the way I would implement things in classes
to pervade my thought.
Of course, I am happy with and fully understand the problems that are
not specific to a car, e.g. of contact patches in a 3d world and how
computer programs approximate them, of how torque and linear forces are
related, etc. If I wasn't, I don't think this would be the place to ask.
I am only a single person and am doing this to try and create games. I
am not imagining for a second that I could ever create something as
realistic as Gran Turismo or Grand Prix Legends, but I certainly don't
want to settle for Ridge Racer type dynamics.
As I understand it, the bedrock of simulating a car engine is the
flywheel. At any given time it has a particular RPM and a particular
torque. Torque may be derived from RPM and for simple simulation
purposes this can be done using a simple graph lookup. The graph will
appear to be an upward curve, peaking towards its end although maximum
torque is not output at maximum RPM. RPM is evolved over time as a
function of flywheel torque (hence this is a differential equation),
throttle and any external torques being applied. Engine whine is
principally a function of flywheel RPM.
Output torque from the flywheel is scaled according to throttle. It then
goes through the transmission before reaching the wheels. Some energy is
lost there, decreasing total power output.
Gears are applied and are usually described by their gear ratio - in
real life a measure of relative cog sizes which for the purposes of
simulation means a number with which to multiply torque and divide RPM.
Hence power output is not affected by gear ratio. Low gears tend to have
low values greater than 1 (as RPM is sacrificed for torque to get the
thing going) and high gears tend to have values between 0 and 1 (as the
car has built up momentum and the aim is to maximise RPM).
That information is passed on to the tyres. I shall ignore the
possibility of sideways forces for the time being.
At any instant they have a linear velocity obviously derived from the
motion of the main vehicle. Based on the RPM they are being driven at,
their radius and the RPM output to them a slip ratio can be computed.
The slip ratio and the output torque together combine, in practical
implementation terms via a graph lookup that relates slip ratio to a
torque scaler, to create a linear force on the tyre and, as a result,
the car body. Every action has an equal and opposite reaction, so
whatever force is applied acts back up through the transmission to the
flywheel as an external torque affecting the current engine RPM.
The "slip ratio" formulation of tyre/surface interaction is an emulation
of the real world that seems to be credited to Pacejka. Since
calculation requires a divide by linear velocity, it is hard to deal
with at low speeds - at speed 0 it is undefined and near 0 it can play
havoc with numerical accuracy due to the very large numbers involved. So
it is common to approximate tyre reactions at low speeds using a spring
model.
A spring model can be implemented by obtaining the difference between
real linear velocity and "intended" linear velocity (i.e. that implied
as a result of output RPM and tyre radius) and applying a force
calculated as though a spring with natural length 0 were stretched to a
size proportional to the difference in velocities. The spring
coefficient is derived in some way from torque. Presumably because this
is a quick fix to make things work in an unimportant area of most car
games - namely low speed driving - then whatever processing of the
numbers that appears to work is acceptable.
Sideways forces act similarly to the forward relative ones described
above, except that RPM isn't a factor - they can be derived purely from
the wheel's linear velocity as any sideways motion is pure slip.
The traction circle limits total traction. Thinking about it
pictographically, if the forwards and sideways forces are combined to
make a 2d vector from the origin then that vector is clipped if its
endpoint is outside of the traction circle. I have to admit that I'm
sufficiently new to this that I am not sure if the circle is always a
genuine circle or if it may be an ellipse with a minor and major radius.
It is the effects of the traction circle that tends to cause sliding
towards the outside of corners approached at speed.
-Thomas