Graphics Reference
In-Depth Information
public virtual void FixedUpdate()
{
UpdatePhysics();
}
public virtual void UpdateEngineAudio()
{
// this is just a 'made up' multiplier value applied to
// mySpeed.
engineSoundSource.pitch= 0.5f + ( Mathf.Abs( mySpeed ) *
0.005f );
}
public virtual void UpdatePhysics()
{
CheckLock();
// grab the velocity of the rigidbody and convert it into
// flat velocity (remove the Y)
velo= myBody.angularVelocity;
// convert the velocity to local space so we can see how
// fast we're moving forward (along the local z axis)
velo= transform.InverseTransformDirection(myBody.velocity);
flatVelo.x= velo.x;
flatVelo.y= 0;
flatVelo.z= velo.z;
// work out our current forward speed
mySpeed= velo.z;
// 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;
rearWheelLeft.brakeTorque = 0;
rearWheelRight.brakeTorque = 0;
frontWheelLeft.steerAngle = steerMax * steer;
frontWheelRight.steerAngle = steerMax * steer;
// drop out of this function before applying
// the 'regular' non-reversed values to the
// wheels
return;
}
}
// apply regular movement values to the wheels
rearWheelLeft.motorTorque = accelMax * motor;
rearWheelRight.motorTorque = accelMax * motor;
Search WWH ::




Custom Search