Sandbox Logo

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 );
		}
	}
}

Wheel Collider

Created
7/11/2024
Updated
8/10/2024
In Collections
Referenced By
Dependencies
Reviews
🥇 x 1