Skip to main content
Game Physics – Complete Beginner to Advanced Guide
CHAPTER 10 Intermediate

Vehicle Physics

Updated: May 16, 2026
35 min read

# CHAPTER 10

Vehicle Physics

1. Introduction

Programming a bipedal character is mostly about faking physics to make jumping feel responsive. Programming a car, however, requires deep simulation. A vehicle is a heavy Rigidbody resting on four independent points of suspension, propelled by rotational friction, and steered by angling the front contact points. Attempting to build a car by simply pushing a box with AddForce results in a vehicle that flips over on every turn and slides like it's on ice. In this chapter, we will master Vehicle Physics. We will explore the specialized WheelCollider component, calculate Motor Torque, manage suspension springs, and learn how to tune friction to achieve satisfying drifts.

2. Learning Objectives

By the end of this chapter, you will be able to:
  • Understand the architecture of a physics-based vehicle setup.
  • Utilize the WheelCollider component to simulate suspension and friction.
  • Apply MotorTorque to propel a vehicle forward.
  • Apply SteeringAngle to turn the vehicle realistically.
  • Manipulate Center of Mass to prevent cars from constantly flipping over.

3. The Architecture of a Virtual Car

A proper vehicle in a game engine requires a specific hierarchy:
  1. 1. The Chassis: The main 3D model of the car. It has a single massive Rigidbody and a BoxCollider to represent the body.
  1. 2. The Wheels (Logic): Four empty GameObjects, each containing a WheelCollider component. These simulate the suspension and tire friction.
  1. 3. The Wheels (Visuals): The 3D tire meshes. The C# script must constantly copy the position and rotation from the logical WheelCollider and apply it to the visual mesh so they spin.

4. The Wheel Collider Component

The WheelCollider is a highly specialized physics component. It does not act like a standard solid sphere. Instead, it shoots a mathematical raycast straight down to the floor to simulate a Suspension Spring.
  • Suspension Distance: How far the wheel can travel up and down.
  • Spring Force: How violently the car bounces back up when it hits a bump.
  • Damper: How quickly the bouncing stops. (Without damping, the car will bounce endlessly like a pogo stick).

5. Driving and Steering (Torque)

You do not push the car's body. You spin the wheels.
  • MotorTorque: The rotational force applied to the wheel to move the car forward.
  • BrakeTorque: The force applied to stop the wheel from spinning.
  • SteerAngle: Turning the front wheels left or right (in degrees).
csharp
12345678910111213141516171819
public WheelCollider frontLeftWheel;
public WheelCollider frontRightWheel;
public float motorForce = 1500f;
public float steerForce = 30f;

void FixedUpdate()
{
    // 1. Get Input
    float vertical = Input.GetAxis("Vertical");     // Gas pedal (W/S)
    float horizontal = Input.GetAxis("Horizontal"); // Steering wheel (A/D)

    // 2. Apply Gas to Front Wheels (Front-Wheel Drive)
    frontLeftWheel.motorTorque = vertical * motorForce;
    frontRightWheel.motorTorque = vertical * motorForce;

    // 3. Apply Steering Angle
    frontLeftWheel.steerAngle = horizontal * steerForce;
    frontRightWheel.steerAngle = horizontal * steerForce;
}

6. The Center of Mass (Preventing Flips)

The most common bug when building a car: the moment you turn a corner, the car rolls over. By default, an engine places the Center of Mass exactly in the geometric center of the box.
  • To make a car handle like an arcade racer, you must lower the Center of Mass artificially using C#. By putting the weight closer to the floor, it becomes almost impossible to flip.
carRigidbody.centerOfMass = new Vector3(0, -0.5f, 0);

7. Drifting and Friction

A tire has two friction directions:
  1. 1. Forward Friction: How much the tire grips when accelerating.
  1. 2. Sideways Friction: How much the tire grips when sliding horizontally.
To make a car drift, you lower the Sideways Friction (specifically the stiffness value) on the rear wheels when the player hits the handbrake!

8. Visual Learning: Vehicle Setup

txt
12345678
       [ Center of Mass ] (Artificially lowered)
              |
[ Body BoxCollider & Rigidbody ]
     /                  \
[Wheel FL]          [Wheel FR]  <-- SteerAngle applied here
  (Spring)            (Spring)
     |                  |
================================== (The Road)

9. Best Practices

  • Separate Logic from Visuals: The WheelCollider is invisible. You must write a C# loop that calls wheelCollider.GetWorldPose(out pos, out rot) and applies that exact position and rotation to your 3D tire models every frame so they spin visually!

10. Common Mistakes

  • Mass Discrepancies: A real car weighs 1,500kg. If you leave your Rigidbody mass at 1kg and apply a MotorTorque of 1,500, the car will instantly accelerate to the speed of light and break the physics engine. Always use realistic mass values (e.g., 1000kg to 2000kg) when tuning vehicle suspension.

11. Mini Project: Build an Arcade Drifter

Objective: Apply a massive sideways impulse to initiate a drift. If configuring complex WheelColliders is too much for a simple arcade game, you can fake it using a standard Rigidbody!
csharp
123456789101112131415161718192021222324
class HoverCarDrifter
{
    public Rigidbody rb;
    public float speed = 2000f;
    public float turnSpeed = 100f;

    void FixedUpdate()
    {
        // 1. Move forward
        rb.AddRelativeForce(Vector3.forward * Input.GetAxis("Vertical") * speed);

        // 2. Rotate car (Steering)
        float turn = Input.GetAxis("Horizontal");
        transform.Rotate(0, turn * turnSpeed * Time.deltaTime, 0);

        // 3. Fake the Drift
        // A real car has friction stopping it from sliding sideways.
        // We calculate the sideways velocity and kill 95% of it!
        Vector3 rightVelocity = transform.right * Vector3.Dot(rb.velocity, transform.right);
        
        // Subtract the sideways slide to emulate tire grip
        rb.velocity -= rightVelocity * 0.95f; 
    }
}

12. Practice Exercises

  1. 1. Why must the Center of Mass be artificially lowered in a racing game?
  1. 2. What specific physics component is used to simulate a car's suspension spring and tire friction?

13. MCQs with Answers

Question 1

When programming a car using a standard WheelCollider setup, how do you propel the car forward?

Question 2

Your car drives fine in a straight line, but the moment you press "A" or "D" to turn, the car violently rolls over onto its roof. What is the most likely physics configuration issue?

14. Interview Questions

  • Q: Explain the mechanical difference between a standard BoxCollider and a specialized WheelCollider in a game engine. How does a WheelCollider utilize Raycasts to simulate a suspension spring?
  • Q: A racing game requires an "e-brake" drift mechanic. Explain how you would manipulate the Sideways Friction curves of the rear WheelColliders via C# to initiate a drift.
  • Q: Why is tuning realistic vehicle mass (e.g., 1,500kg) critical for a WheelCollider-based car, whereas a kinematic platformer character can remain at 1kg?

15. FAQs

Q: AAA driving games feel incredible. Do they use standard WheelColliders? A: Rarely. Standard WheelColliders are notoriously finicky. AAA studios (like Playground Games for *Forza*) write completely custom physics integration in C++, calculating complex tire deformation algorithms (like the Pacejka Magic Formula) from scratch!

16. Summary

In Chapter 10, we put our physics knowledge behind the wheel. We abandoned AddForce in favor of the specialized WheelCollider component, allowing us to simulate real-world suspension, spring damping, and tire friction. We propelled the car using motorTorque and steered using steerAngle. Most importantly, we learned the industry trick of artificially lowering the Center of Mass to prevent our high-speed arcade racers from rolling over on every turn.

17. Next Chapter Recommendation

Our vehicles are solid blocks of metal. But what happens when an organic, multi-jointed character gets hit by one? Proceed to Chapter 11: Ragdoll Physics and Character Reactions.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·