Wheel Collider

Collider for ground vehicles, with built-in collision detection, basic suspension physics, and a basic tire friction model.

Usage


Create a car GameObject with a Rigidbody component, a collider, and a model.

Create four empty child GameObjects with just models. These shouldn't have colliders or be rigidbodies. 

Attach a Component script that controls the car on the car GameObject, for example:
public sealed class Car : Component

{
[RequireComponent] public Rigidbody Rigidbody { get; set; }

private List<Wheel> Wheels;

protected override void OnEnabled()
{
Wheels = Components.GetAll<Wheel>( FindMode.EverythingInSelfAndDescendants ).ToList();
}

protected override void OnFixedUpdate()
{
float verticalInput = Input.AnalogMove.x;
float torque = verticalInput * 10000f;

// Apply torque to each drive wheel
foreach ( Wheel wheel in Wheels )
{
wheel.ApplyMotorTorque( torque );
}
}
}