Graphics Reference
In-Depth Information
rearWheelLeft.brakeTorque = brakeMax * brake;
rearWheelRight.brakeTorque = brakeMax * brake;
frontWheelLeft.steerAngle = steerMax * steer;
frontWheelRight.steerAngle = steerMax * steer;
}
public void CheckLock()
{
if (isLocked)
{
// control is locked out and we should be stopped
steer = 0;
brake = 0;
motor = 0;
// hold our rigidbody in place (but allow the Y to move so
// the car may drop to the ground if it is not exactly
// matched to the terrain)
Vector3 tempVEC = myBody.velocity;
tempVEC.x = 0;
tempVEC.z = 0;
myBody.velocity = tempVEC;
}
}
public virtual 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 );
}
}
5.3.1 Script Breakdown
The class derives from ExtendedCustomMonoBehavior (as discussed in Chapter 4), which
adds a few commonly used variables.
Each WheelCollider variable is named based on its intended position: front-
WheelLeft, frontWheelRight, rearWheelLeft, and rearWheelRight. For the script to
function correctly, WheelColliders need to be referenced (dragged and dropped) into
the correct variables in the Unity Inspector window on the vehicle script:
using UnityEngine;
using System.Collections;
public class BaseVehicle : ExtendedCustomMonoBehavior
{
public WheelCollider frontWheelLeft;
public WheelCollider frontWheelRight;
public WheelCollider rearWheelLeft;
public WheelCollider rearWheelRight;
Search WWH ::




Custom Search