We add forces to the rigid body and the physics system uses these to compute the object's new position.
Traction force
Tractive force, the force delivered by the engine to the drive wheels. Actually a torque will be applied to each drive wheel; this torque will be the result of engine torque converted via the gear and differential. Unfortunately, quite some energy is lost in the transmission process because of all those gears and couplings.
Torque is the cross product between the distance vector (the distance from the pivot point to the point where force is applied) and the force vector. Equation of torque:
To extract the drive force from the torque applied to the drive wheel we must divide torque by wheel radius which will be the distance from the pivot point to the point where force is applied, and the force is applied with a 90 degree angle so the sin θ from the torque equation will be 1.
τengine – torque of the engine at current RPM [Nm];
ng – current gear ratio;
nd – differential ratio;
et – transmission efficiency;
rwheel – radius of the wheel [m].
Now let’s explain the traction force, for example if the car drives forward the drive wheels push backwards on the road surface with Fw, in reaction, the road surface pushes back in a forward direction and this will be the tractive force Ft which by Newton’s third law it will be equal with the force delivered by the wheels but of opposite direction.
The torque that an engine can deliver depends on the speed at which the engine is turning, commonly expressed as rpm (revolutions per minute). The relationship torque versus rpm is not a linear relationship, but is usually provided as a curve known as a torque curve (the exact shape and height of the curve is specific for each engine type, it is determined by engine tests).
In Unity we can use AnimationCurve to simulate torque at different RPMs (Engine-Torque Curve).
Note that the torque curve chosen starts with 150 Nm at 800 rpm and peaks at about 4000 rpm with a torque of 270Nm. The curve is only defined in the range 800 – 6150 rpm, in this particular case, because that is the chosen operating range of the engine. Any lower, and the engine will stall, any higher (above the so-called "redline"), and you'll damage it, and inside the code the torque will be evaluated only between this limits.
Note, the maximum torque the engine can deliver at a given rpm depends also on the throttle position and is a fraction between 0.0f and 1.0f for the maximum. So the equation for traction force above will become:
At this point if we don’t want to get in calculation the tires slippage then we are done with the traction force.
Next we will discuss about resistance forces, because if this were the only force applied to the car then the car would accelerate to infinite speeds.
Aerodynamic drag
Aerodynamic drag, by far the most important resistance force, especially if the car moves at high speeds, because it is proportional to the square of the velocity as we will see in the next equation which yields the magnitude of this force:
Cd – is the coefficient of drag that is it is different from car to car, it is dependent on the shape of the car body and is determined at design time via tests in wind tunnels. To find the coefficient of drag a search on Google, or the car manufacture book will tell us the value for a specific car
ρ – this Greek symbol represents the air density, the value of this changes with the temperature of the air, a table of values for different air temperatures can be found on Wikipedia page https://en.wikipedia.org/wiki/Density_of_air
v – represents the velocity magnitude (speed)
A – is the frontal area of the car, which again is different from car to car, but again a search on Google or the car manufacture book can tell us the value for a specific car
The vector equation will look like this:
Note in the above equation v is a vector, named velocity, the scalar or the magnitude of this vector is named speed.
Rolling resistance
Rolling resistance is a force due to contact of the wheel with the surface of the ground, in order to understand it we need to understand first the normal force.
To define normal force we will first define weight as a force, maybe you heard people expressed their weight in kilograms but the kilogram is the unit of measure for mass not weight, and the mass is the object resistance to acceleration, it is the intrinsic property of the object and it doesn't change from one environment to the next. On the other hand weight changes from one environment to the next, it depends on the gravitational field of that environment, it is actually the force applied to that object due to gravity, is therefore a vector quantity measured in the SI units in N
m – mass of the object in kg;
g – acceleration due to gravity.
In a simple case such as an object resting upon a flat surface, the normal force on the object is equal but in opposite direction to the weight:
For an inclined plane we must multiply the cosine of inclination from horizontal axis, the magnitude of this force is given by
Note, the normal force is always acting on the direction of plane normal.
The other portion of the force that is not normal to the plane, it is acting parallel to the plane and it will cause an object to slide
In Unity environment the normal and weight force is computed automatically, but still we need the normal force to calculate rolling resistance.
Rolling resistance is a contact force that resists the rolling motion of an object, it is actually caused by the fact that the wheels come in contact with the ground and both objects deform to some degree because of the force the exert on each other.
In simulations is usually acceptable to approximate the rolling resistance of each wheels as a single resistance force acting against the velocity of the car.
The magnitude of this force can be approximated using the magnitude of the normal force as:
A table of rolling resistance coefficients can be found on Wikipedia at https://en.wikipedia.org/wiki/Rolling_resistance
Longitudinal forces
The sum of all forces acting longitudinal
Braking
We can implement braking in our simulation by substitute traction force with braking force which is oriented in the opposite direction, but we shall keep in mind that as soon as the speed is reduced to zero, keep the car in that state otherwise the car will end up going in reverse.
Where Fb equation is:
u - unit length direction vector;
Cb – brake force magnitude (in Newtons);
Tf – brake severity 0.0f … 1.0f.
Braking can be implemented also as a torque.
Cbt – brake torque (Nm);
Tf – brake severity 0.0f … 1.0f.
Equation for angular deceleration, similar to angular acceleration where we use motor torque instead of brake torque
τb – brake torque
I – moment of inertia
Angular velocity when braking
Engine braking
The engine will also slow the car down as air intake is restricted when the throttle is released.
τeb – torque due to engine braking
μeb – coefficient of engine braking
Ωe – engine RPM
Final brake calculations
To calculate the final braking if the throttle is released we shall also add engine braking, we can ignore drivetrain friction cause it influence braking by a very small amount.
Slip ratio
Angular velocity (ω) describes the rate at which an object is rotating. The magnitude of angular velocity is measured in SI unit of Radians Per Second (rad/s).
On a rear wheel drive vehicle the rear wheels will always rotate faster than the front wheels (free rolling wheels), because they are slipping with respect to the road surface, it is this friction caused by the drive wheels slip on the road surface to generate traction force.
The angular velocity of a free rolling wheel is given by the following equation:
v – speed of car in wheel forward direction (m/s)
rw – radius of wheel (m)
Angular velocity of a drive wheel:
ωw – angular velocity
α – angular acceleration
Δt – time interval
Angular acceleration of a drive wheel:
τm – motor torque
I – moment of inertia (approximate wheel as a cylinder and use that formula)
Wheel RPM
Wheel friction curve (slip ratio curve)
Unity has built in support for wheel friction curve inside wheel colliders. So our work here is made easier, I won’t enter here in the theory because we just need to configure wheel collider’s parameters and we have realistic traction force, slippage, sideways traction, power sliding, turning.
Wheel friction curve show us that with high slip we get less traction force and car accelerates more slowly.
Slippage appears when there is a difference between tangential velocity of the wheel and that of the car body (ex: accelerate aggressively from stand still), or speed of the wheels are different from speed of the car body (ex: braking and the car is still traveling under its inertia). Slip ratio equation:
Vlong – car speed in wheel direction
Slip speed equation:
Engine RPM calculation
We need the rpm to calculate the engine's max torque and from there the engine's actual applied torque. In other words, now we need to know has fast the engine's crankshaft is turning.
One way is to calculate this back from the drive wheel rotation speed. If the engine's not declutched, the crankshaft and the drive wheels are physically connected through a set of gears. If we know the rpm, we can calculate the rotation speed of the drive wheels, and vice versa!
Calculate Ackermann angles for steering wheels
A picture is worth a thousand words:
Weight Transfer
An important effect when accelerating or braking is the effect of dynamic weight transfer. When braking hard the car will nosedive. During accelerating, the car leans back.
I will not put any theory in here because this effect is done behind the scene in Unity, when using wheel colliders.
Suspensions
Handled by Unity wheel collider, see links bellow.
NVidia PhysX Documentation
http://docs.nvidia.com/gameworks/content/gameworkslibrary/physx/guide/Manual/Vehicles.html
Wheel collider’s source
http://wiki.unity3d.com/index.php?title=WheelColliderSource
Unity Manual: Wheel Collider
https://docs.unity3d.com/Manual/class-WheelCollider.html