Graphics Reference
In-Depth Information
5.3 Wheeled Vehicle
The BaseVehicle.cs script relies on Unity's built-in WheelCollider system. WheelCollider com-
ponents are added to gameObjects positioned in place of the wheels supporting the car body.
The WheelCollider components themselves do not have any visual form, and meshes repre-
senting wheels are not aligned automatically. WheelColliders are physics simulations; they
take care of all of the physics actions such as suspension and wheel friction.
The Unity documentation describes the WheelCollider as
…a special collider for grounded vehicles. It has built-in collision detection, wheel phys-
ics, and a slip-based tire friction model.
he physics and math behind the friction system are beyond the scope of this topic,
though thankfully, the Unity documentation has an extensive investigation of the subject
on the WheelCollider page in the online help (http://docs.unity3d.com/Documentation/
Components/class-WheelCollider.html).
The BaseVehicle.cs script uses four WheelColliders for its drive (in the example games,
these are attached to empty gameObjects), and the actual orientation of wheel meshes is
dealt with by a separate script called BaseWheelAlignment.cs and will be explained in full
later on in the chapter.
BaseVehicle.cs looks like this:
using UnityEngine;
using System.Collections;
public class BaseVehicle : ExtendedCustomMonoBehavior
{
public WheelCollider frontWheelLeft;
public WheelCollider frontWheelRight;
public WheelCollider rearWheelLeft;
public WheelCollider rearWheelRight;
public float steerMax = 30f;
public float accelMax = 5000f;
public float brakeMax = 5000f;
public float steer = 0f;
public float motor = 0f;
public float brake = 0f;
public float mySpeed;
public bool isLocked;
[System.NonSerialized]
public Vector3 velo;
[System.NonSerialized]
public Vector3 flatVelo;
public BasePlayerManager myPlayerController;
Search WWH ::




Custom Search