Graphics Reference
In-Depth Information
{
accelMax= originalAccelMax*0.25f;
}
}
The last part of the function will update the pitch of the engine audio based on the
current speed of the vehicle. This happens in the UpdateEngineAudio() function, which
is called here:
// update the audio
UpdateEngineAudio();
}
The GetInput() function overrides the original one found in the BaseVehicle script.
This one works almost the same, with additions of the respawning functionality and
weapon support:
public override void GetInput()
{
// calculate steering amount
steer= Mathf.Clamp( default_input.GetHorizontal() , -1, 1 );
// how much accelerator?
motor= Mathf.Clamp( default_input.GetVertical() , 0, 1 );
// how much brake?
brake= -1 * Mathf.Clamp( default_input.GetVertical() , -1, 0 );
The default_input object is of type Keyboard_Input, which has support for respawn.
Finding out whether the user is hitting the respawn key is a call to default_input.
GetRespawn(), which will return true or false. If the user hits the respawn key, the vehicle
is not respawning already and canRespawn is true, the Respawn() function is called to
reset the car, and the variables isRespawning and canRespawn are set to disable any fur-
ther respawning. They will both be reset when the call to resetRespawn is made, as sched-
uled here by an Invoke() function set for 2 s time:
if( default_input.GetRespawn() && !isRespawning &&
canRespawn)
{
isRespawning=true;
Respawn();
canRespawn=false;
Invoke ("resetRespawn",2);
}
To keep the flexibility of still being able to work without a weapon controller, the fir-
ing input code starts with a null check on weaponControl. If default_input.GetFire() is
true and canFire is set, weaponControl.Fire() is called to make the current weapon do its
thing:
// first, we make sure that a weapon controller exists
// (otherwise no need to fire!)
if( weaponControl != null )
Search WWH ::




Custom Search