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 withAddForce 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
WheelCollidercomponent to simulate suspension and friction.
-
Apply
MotorTorqueto propel a vehicle forward.
-
Apply
SteeringAngleto 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.
The Chassis: The main 3D model of the car. It has a single massive
Rigidbodyand aBoxColliderto represent the body.
-
2.
The Wheels (Logic): Four empty GameObjects, each containing a
WheelCollidercomponent. These simulate the suspension and tire friction.
- 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
TheWheelCollider 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
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. Forward Friction: How much the tire grips when accelerating.
- 2. Sideways Friction: How much the tire grips when sliding horizontally.
stiffness value) on the rear wheels when the player hits the handbrake!
8. Visual Learning: Vehicle Setup
txt
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
1kgand 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
12. Practice Exercises
- 1. Why must the Center of Mass be artificially lowered in a racing game?
- 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 abandonedAddForce 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.