Game Development Reference
In-Depth Information
Listing 43:
Control and other functions of
PhysicsCarDriver
script
AccelerateForward()
is a public function that can be used by other scripts to set
accel-
erateForward
flag. This function protects the script from a contradictory input by set-
ting
accelerateBackwards
to
false
. The same mechanism is used by
AccelerateBackwards()
,
SteerRight()
,
SteerLeft()
and
Brake()
functions.
UpdateWheelTorque()
function takes a
wheel collider and a torque amount to apply to it. After applying the toque, it checks the
new speed of the wheel in RPM. If the speed is greater than
maxRPM
or less than
-maxRe-
verseRPM
, a zero torque is applied to prevent the vehicle from exceeding its speed limits.