Game Development Reference
In-Depth Information
The same mechanism is used with steering in lines 89 through 97: if steerRight or steerLeft
flag is set to true , we apply the corresponding steering by calling UpdateSteering() function.
However, if both flags are false , we apply a zero steering to the front wheels. The details
of UpdateSteering() functions are going to be covered shortly. The last section of
FixedUpdate() between lines 101 and 117 handles braking input. If braking flag is true ,
brakesTorque is applied to all wheels, otherwise a brake torque of zero is applied. A torque
can be applied to a wheel collider through motorTorque variable. The negative value means
that we want the wheel to spin counter clockwise, hence moving the vehicle backwards.
Unlike the case of applying motor torque, brake torque does not need to check any condi-
tions before being applied to the wheels. This sounds logical if you recognize the fact that
nothing bad happens when pressing the brakes pedal of a stopped car. The last part of Phys-
icsCarDriver is shown in Listing 43, and it covers all other functions of the script.
Search WWH ::




Custom Search