Graphics Reference
In-Depth Information
// if we are moving slow, apply some extra force to turn the
// car quickly so we can do donuts (!) - note that since
// there is no 'ground detect' it will apply it in the air,
// too (bad!)
if( mySpeed < TurnTorqueHelperMaxSpeed )
{
myBody.AddTorque( new Vector3( 0, steer *
myBody.mass * turnTorqueHelper * motor, 0 ) );
}
}
The global race manager tracks the race state and whether or not the race is run-
ning, but it will also communicate it to each player's race controller. LateUpdate() starts
by getting the state of the race from raceControl.raceRunning and storing it into a variable
named isRaceRunning:
public override void LateUpdate()
{
// get the state of the race from the race controller
isRaceRunning= raceControl.raceRunning;
If the race is running, this function will go on to do all of the things we need to do
during the race:
if(isRaceRunning)
{
We regularly call Check_If_Car_Is_Flipped() to check to see whether the car's rota-
tion is at irregular angles, to see whether it has flipped and needs respawning:
// check to see if we've crashed and are upside
// down/wrong(!)
Check_If_Car_Is_Flipped();
Whenever the race is running on an AI, gunControl should be able to fire, so gun-
Control.canControl is set to true:
// make sure that gunControl has been told it can fire
if(isAIControlled)
gunControl.canControl=true;
When this script is updating an AI player, inputs to drive the vehicle come from the
GetAIInput() function. Otherwise, GetInput() will provide inputs from the default_input
object:
// we check for input in LateUpdate because Unity
// recommends this
if(isAIControlled)
{
GetAIInput();
} else {
GetInput();
}
} else {
Search WWH ::




Custom Search