Skip to content
ReadySpawn

How to make a driving game in Unity: an arcade car controller

By Imersa Studios · Updated

For an arcade feel, drive a Rigidbody with forces: accelerate along the car's forward direction, turn based on speed and cancel sideways velocity for grip. Use WheelColliders only when you need realistic suspension. The script below is a working starting point.

1. Set up the car

  • Create a car mesh with the pivot at its centre, and add a BoxCollider.
  • Add a Rigidbody: mass around 1000, drag low, angular drag moderate.
  • Add the script below and a flat ground collider to test.

2. The controller

using UnityEngine;

[RequireComponent(typeof(Rigidbody))]
public class ArcadeCar : MonoBehaviour
{
    public float acceleration = 25f;
    public float maxSpeed = 30f;
    public float turnSpeed = 90f;
    public float grip = 6f;

    Rigidbody rb;
    float throttle, steer;

    void Awake()
    {
        rb = GetComponent<Rigidbody>();
        rb.centerOfMass = new Vector3(0f, -0.5f, 0f); // low centre = harder to flip
    }

    void Update()
    {
        throttle = Input.GetAxis("Vertical");
        steer = Input.GetAxis("Horizontal");
    }

    void FixedUpdate()
    {
        Vector3 forward = transform.forward;
        float speed = Vector3.Dot(rb.linearVelocity, forward);

        if (Mathf.Abs(speed) < maxSpeed)
            rb.AddForce(forward * throttle * acceleration, ForceMode.Acceleration);

        // Steering scales with speed so the car cannot spin on the spot.
        float dir = speed < -0.1f ? -1f : 1f;
        float turn = steer * turnSpeed * Mathf.Clamp01(Mathf.Abs(speed) / 5f) * dir;
        rb.MoveRotation(rb.rotation * Quaternion.Euler(0f, turn * Time.fixedDeltaTime, 0f));

        // Cancel sideways velocity: this is the grip.
        Vector3 lateral = Vector3.Dot(rb.linearVelocity, transform.right) * transform.right;
        rb.AddForce(-lateral * grip, ForceMode.Acceleration);
    }
}

This uses Unity 6's linearVelocity. In older versions use velocity. It uses the classic Input Manager axes; with the newer Input System, read the same values from your actions.

3. Tune the feel

To getChange
Drifty, loose carLower grip (2 to 3)
Planted, sporty carRaise grip (8 to 12) and lower the centre of mass
Heavier feelRaise mass and lower acceleration
Tighter turningRaise turnSpeed

Add a camera that follows behind with some lag, and engine audio that rises with speed, to sell the feel.

4. WheelColliders or not?

WheelColliders simulate suspension and tyre friction, which suits racing sims but takes tuning. For open-world crime games and arcade racers, the force-based approach above is easier to get fun.

5. Add traffic

A road with no cars feels dead. Traffic System gives you AI cars that follow lanes and stop at junctions, so you can focus on your own car. Read how to make NPC pedestrians and traffic AI to see how it works.

Questions

Who wrote this

Imersa Studios builds the Unity systems, low poly packs and field guides sold on itch.io. The code and techniques here come from shipping those products. More about the studio.