Graphics Reference
In-Depth Information
PlayerFinished() lets the player know that it is finished racing. As well as disabling
firing with canFire set to false, everything that might drive or steer the player is disabled
in this function, too:
public void PlayerFinished()
{
// disable this vehicle
isAIControlled= false;
canControl= false;
canFire= false;
AIController.canControl= false;
motor= 0;
steer= 0;
}
To keep the car upright, the Check_If_Car_Is_Flipped() function simply checks the
localEulerAngles of the car to see whether its rotations are out of the ordinary. These val-
ues are not exactly scientific; the rotation values it checks against were decided by trial and
error until it felt right and detected most regular cases:
void Check_If_Car_Is_Flipped()
{
if((myTransform.localEulerAngles.z > 80 &&
myTransform.localEulerAngles.z < 280) || (myTransform.localEulerAngles.x >
80 && myTransform.localEulerAngles.x < 280)){
As the vehicle is at a strange angle, resetTimer is incremented by Time.deltaTime.
This provides a reference as to how long the vehicle has been potentially flipped:
resetTimer += Time.deltaTime;
} else {
resetTimer = 0;
}
When the resetTimer goes over resetTime, the player will be respawned:
if(resetTimer > resetTime)
Respawn();
}
As the race finishes, PlayerFinishedRace() is called by the race controller, with its final
race position passed in as an integer:
void PlayerFinishedRace( int whichPositionDidFinish )
{
If this player is not controlled by AI, it must be the user. Here the game controller is
told about the end of the game, and then the AI is told to take over control of the vehicle:
if( !isAIControlled )
{
// tell game controller that the game is finished
GameController_MVD.Instance.RaceComplete(whichPositionDidFinish );
Search WWH ::




Custom Search