Graphics Reference
In-Depth Information
during braking and the maximum amount of torque applied as motorTorque during
reversing:
// if we're moving slow, we reverse motorTorque and remove
// brakeTorque so that the car will reverse
if( mySpeed<2 )
{
// that is, if we're pressing down the brake key (making
// brake>0)
if( brake>0 )
{
rearWheelLeft.motorTorque = -brakeMax * brake;
rearWheelRight.motorTorque = -brakeMax * brake;
In reverse mode, no brakeTorque will be applied to the WheelColliders so that the
vehicle is free to move backward:
rearWheelLeft.brakeTorque = 0;
rearWheelRight.brakeTorque = 0;
When the vehicle is reversing, the steering is applied in reverse to switch over the
steering when going backward, as a real car would:
frontWheelLeft.steerAngle = steerMax * steer;
frontWheelRight.steerAngle = steerMax * steer;
If the reverse conditions have been applied to the WheelColliders, this function drops
out before the regular (forward) values are applied:
// drop out of this function before applying the 'regular'
// non-reversed values to the wheels
return;
}
}
In this script, driving the wheels of WheelColliders is a case of applying motorTorque
and brakeTorque and setting the steerAngle:
// apply regular movement values to the wheels
rearWheelLeft.motorTorque = accelMax * motor;
rearWheelRight.motorTorque = accelMax * motor;
rearWheelLeft.brakeTorque = brakeMax * brake;
rearWheelRight.brakeTorque = brakeMax * brake;
frontWheelLeft.steerAngle = steerMax * steer;
frontWheelRight.steerAngle = steerMax * steer;
}
The CheckLock() function looks to see whether the Boolean variable isLocked is set to
true; when it is, it freezes all inputs to zero and zeroes the x and z velocities of the vehicle's
rigidbody. The y velocity is left as is, so that gravity will still apply to the vehicle when it is
being held in place. This is important at the start of a race when the vehicle is being held
until the 3, 2, 1 counting in finishes. If the velocity along the y -axis were zeroed too, the
Search WWH ::




Custom Search