Game Development Reference
In-Depth Information
The second important thing to do in Start() is to change the center of mass of the rigid body,
so it takes the new position from the local position of centerOfMass .
After the initialization we move to the update function. This time we deal with a new vari-
ation of update, which is FixedUpdate() . This function is guaranteed by Unity to give the
same deltaTime at each iteration; so it is used for tasks that depend on accurate timing such
as physics simulation and collision detection. Therefore, we perform all tasks related to
car driving inside FixedUpdate() . In lines 59 through 86, we check accelerateForward and
accelerateBackwards flags. If the value of either flag is true , we apply the max motor torque
to front and back wheels. Notice that we apply the torque through UpdateWheelTorque()
function, which is responsible for checking RPM limits before applying the torque, as we
are going to see soon. After applying the torque we reset the corresponding flag to false .
If both accelerateForward and accelerateBackwards are false , this means that there is no
command to move the car. Consequently, we apply a torque of zero to all wheels.
Search WWH ::




Custom Search