Driving on Terrain: Vehicles and Physics

Overview

Racing games, delivery games and open-world adventures all have one thing in common: something with wheels moving over the ground. In this tutorial, you will add a toy car to a scene with a terrain, set it up in Quorum Studio with a Vehicle controller, and drive it over the hills you made. Along the way you will see how a game turns a car into physics: a body with weight, four wheels on springs, an engine that pushes and brakes that hold, and tires that grip until they slide.

Goals

By the end of this lesson, you can

  • Explain how a game models a car: a body, wheels on springs, an engine, steering and brakes
  • Set up a car in Quorum Studio and drive it with a short program
  • Describe how mass, springs, grip and the width between the wheels change the way a car drives
  • Change one setting at a time and describe what it does

Warm up

Think about riding in a car or on a bike over a bumpy road. What keeps you from feeling every single bump? What makes a car skid on ice, or tip over on a sharp turn? Make a list of the parts of a real car that matter for how it moves.

Vocabulary

You will be learning about the following vocabulary words:

Vocabulary
TermDefinition
VehicleSomething that carries people or things and moves over the ground, such as a car. In Quorum, a Vehicle joins a body to its wheels.
ChassisThe main body of a vehicle. In a game it has the vehicle's weight and its collision shape.
ControllerA setting that tells a game how an item moves, such as driving it as a car. In Quorum Studio, a model's Controller section sets it.
Physics bodyThe invisible shape a game's physics moves, such as a box for a car. The model you see rides on it.
SuspensionThe springs and shock absorbers between a vehicle's wheels and its body, which smooth out bumps. In Quorum, each wheel is a Suspension.
SpringSomething that pushes back harder the more it is squeezed, so a wheel pressed up by a bump pushes the body back up.
DampingSlowing a movement down so it doesn't keep bouncing, the way a shock absorber stops a car bouncing after a bump.
RaycastSending an invisible straight line from a point to see what it hits, and how far away.
Raycast vehicleA vehicle whose wheels are raycasts instead of real round objects: each wheel checks the ground with a line straight down, and a spring pushes the body up.
Engine forceHow hard the engine pushes the vehicle along, in newtons.
Friction slipHow much grip a tire has. Push it harder than that sideways, as in a fast turn, and it slides.
Center of massThe point where a body's weight balances. The higher it is, and the closer the wheels are together, the more easily a vehicle tips.
Chase cameraA camera that follows behind and above a moving object.

New Code to Learn

You will be using the following new pieces of code:

New Code to Learn
Quorum CodeCode ExampleExplanation
LoadScene(text path)LoadScene("Scenes/Scene.qs")Loads a scene made in Quorum Studio, with its items, terrain, physics and controllers.
GetSceneController(text name)car = GetSceneController("Car")Returns what a scene built for an item with a controller, such as a car, by the item's name.
SceneController:Reset()car:Reset()Puts a vehicle back where it was placed in the scene, upright and stopped.
SceneController:GetBody()Item3D body = car:GetBody()Returns the physics body the car rides on, which moves when the car drives.
GetStartPosition()car:GetStartPosition()Returns where Reset puts the car.
GetVehicleBehavior()VehicleMovementBehavior driving = car:GetVehicleBehavior()Returns what drives the car with the keys, such as to change its keys.
SetForwardKey(integer key)driving:SetForwardKey(keys:UP)Changes the key that drives forward. SetReverseKey, SetLeftKey and SetRightKey change the others.

CSTA Standards

For teachers · 2026 CSTA K–12 Computer Science Standards

HS-PRO-PD-12

High School · Programming

Create a modular program that uses procedures, external libraries, or objects to improve reusability and readability.

Also in 9 other lessons

HS-PRO-PD-13

High School · Programming

Use documentation, libraries, application programming interfaces (APIs), and other tools in program development.

Also in 5 other lessons

HS-DAT-DI-26

High School · Data & Analysis

Evaluate a data simulation or visualization to answer a data question, inform decision-making, and identify potential limitations.

Also in 2 other lessons

S1-GMD-DD-03

Specialty I · Game Development

Develop an interactive experience to support gameplay.

Also in 1 other lesson

Every standard, and the lessons that cover it

Explore

A car in a game is a physics simulation, built from the same ideas as the falling ball in Properties: mass, forces, gravity and friction. What makes a car special is how those ideas are put together. A heavy body sits on four springs, each spring rests on a wheel, the engine pushes the wheels, the brakes hold them, and the tires grip the ground until they are pushed too hard. Quorum has classes for each of these parts. In this tutorial you will add a toy car to a scene, give it a Vehicle controller in Quorum Studio, and tune how it drives with sliders. A short program then drives it.

How a game car works

A real car's wheels are round, and they roll. Simulating every wheel as a real round object, touching the ground at just the right point and rolling without slipping, is hard for a physics engine to do well, so many games use a shortcut called a raycast vehicle. Quorum's Vehicle class is one.

In a raycast vehicle, the wheels aren't physics objects at all. Each wheel is an invisible line, a raycast, sent straight down from the car's body on every physics step. The line finds out how far away the ground is under that corner of the car. A spring then pushes the body up: the closer the ground, the more the spring is squeezed, and the harder it pushes. This is the car's suspension, and it is why the body rides smoothly over bumps instead of bouncing off them. Damping slows the spring down, the way a shock absorber does, so the car settles after a bump instead of bouncing on and on.

The wheels also push the car along and turn it. The engine's force is applied where each driving wheel touches the ground, the front wheels turn to steer, and each tire grips the ground sideways. If a tire is pushed sideways harder than its grip, which Quorum calls its friction slip, it slides, and the car skids.

In Quorum, the car has two parts that move together. Its physics body is an invisible box that the physics moves; the wheels' rays hang under it. The model, the car you see, rides on the body. Because they are separate, the model can be any shape, and the box can be smaller than it, so it doesn't catch on hills.

Getting the car

The car is the Toy Car, one of the free sample models the Khronos Group shares so that people can test 3D programs. The Khronos Group is the same group that looks after OpenGL, WebGL and Vulkan, and they also created glTF, the file format the car is saved in. The car model was made by Guido Odendahl, and its materials and scene by Eric Chadwick, and they released it under the CC0 license, so anyone may use it in any project.

The car's files are on GitHub, in the Toy Car folder of glTF-Sample-Assets. That folder holds the model in more than one form; this tutorial uses the one in its glTF folder, which is a .gltf text file, a .bin file of shapes, and the images that color the car.

  1. In your project's folder, make a folder named Car at the top of the project.
  2. Open the glTF folder in a web browser. It lists ten files:
    • ToyCar.gltf and ToyCar.bin;
    • ToyCar_basecolor.png, ToyCar_clearcoat.png, ToyCar_emissive.png, ToyCar_normal.png and ToyCar_occlusion_roughness_metallic.png;
    • Fabric_baseColor.png, Fabric_normal.png and Fabric_occlusion.png.
  3. For each file, open it on GitHub and use its Download raw file button, then move the file into your Car folder. All ten files must be in the same folder, because ToyCar.gltf finds the others by name.
  4. Also download the folder's LICENSE.md, from the Toy Car folder, into Car, so the license stays with the model.

Use a scene with a terrain, such as one you shaped and painted in the earlier tutorials, saved as Scenes/Scene.qs.

Giving credit

The car is CC0, so credit isn't required, but it is good practice, as in Terrain Materials and Painting. Add the car to your project's Credits.txt:

Toy Car, by Guido Odendahl (model) and Eric Chadwick (materials and scene),
from the Khronos Group's glTF Sample Assets:
https://github.com/KhronosGroup/glTF-Sample-Assets/tree/main/Models/ToyCar
License: CC0 1.0 (public domain). Used with its blanket hidden.

Adding the car to the scene

  1. Open your scene with a terrain. In the palette, under Custom 3D, choose Custom Model, then choose Car/ToyCar.gltf. A tile named ToyCar is added to a new Project Models group at the top of the palette. The toy is only a few centimeters long, so its tile starts it many times larger, as its description says. The scene keeps the tile, so it is there the next time you open the scene.
  2. Drag the ToyCar tile onto the terrain, or press Enter on it, and place the car.
  3. In the Properties panel, set its Name to Car, and its Scale to 150 for x, y and z, so it's about the size of a real car.
  4. The toy car sits on a blanket, which is its own part of the model. In the Parts card, uncheck Show Fabric. The blanket is hidden, in the editor and in the game, and the model's file isn't changed.

Giving the car a controller

Select the car. In the Controller section, choose Vehicle. The car is fitted at once: a physics box, four wheels and their springs are worked out from the shape of the parts that show. Lines drawn over the car show them, and the car is drawn see-through while they show:

  • a light blue box: the physics body, with an arrow out of its front;
  • orange circles: the front wheels, which steer; yellow circles: the back wheels;
  • green lines: the springs, as long as they are at rest;
  • a pink cross: where the game's camera starts.

The same values are in the Controller section's sliders. The toy car's front points along its own -Z, so if the arrow points out of the back of the car, choose -Z under Front faces, and press Fit to model again.

The Controller section has six cards:

Controller cards
CardWhat it sets
ModelWhich way the model faces, where it sits on the body, and Fit to model
BodyMass, the physics box, scrape friction and damping
WheelsWhere the axles are, how far out and how high the wheels are, their radius, and which wheels the engine turns
SuspensionRest length, stiffness, damping, tire grip and roll influence
DrivingEngine, reverse and brake forces, steering lock, and how quickly steering and throttle change
CameraCamera follows this, behind, above, smoothing and angle

Every change is one step to undo. The car's own Physics card is replaced by a note while it has a controller, since the controller sets its physics.

Physics and gravity

Select the 3D layer itself in the Scene tree. Its Physics section has Physics in games, which turned on when you chose Vehicle, and Gravity x, y and z, which start at 0, -9.8 and 0: Earth's pull, straight down. The editor itself never runs physics; these are for the game.

Where the camera follows from

Choose Game Camera in the Scene tree. The view moves to where the game's camera will start, behind and above the car, facing it. Move it with the camera keys or the mouse; it keeps facing the car, and when you stop, its place becomes the car's Behind, Above and Angle.

The program

Replace the code in Main.quorum with this program:

use Libraries.Game.Game
use Libraries.Game.InputMonitor
use Libraries.Game.Scenes.SceneController
use Libraries.Interface.Events.KeyboardEvent
use Libraries.Interface.Item3D

class Main is Game
    SceneController car = undefined
    InputMonitor monitor
    KeyboardEvent keys

    action Main
        UseVulkan(true)
        StartGame()
    end

    action CreateGame
        LoadScene("Scenes/Scene.qs")
        car = GetSceneController("Car")
        if car = undefined
            output "The scene has no model named Car with a Vehicle controller."
        end
    end

    action Update(number seconds)
        if car = undefined
            return now
        end
        // R, or falling off the edge, puts the car back where it was placed.
        Item3D body = car:GetBody()
        if monitor:IsKeyPressed(keys:R) or body:GetY() < car:GetStartPosition():GetY() - 30
            car:Reset()
        end
    end
end

Run it. The car drops onto its springs where you placed it, and the camera follows from where you set it.

Driving

Driving
ActionWindowsMac
Drive forwardWW
Drive backwardSS
Steer leftAA
Steer rightDD
BrakeSpaceSpace
Put the car back where you placed itRR

The car's driving behavior turns these keys into three commands: throttle, from full reverse to full forward; steering, from full left to full right; and braking. Every key can be changed. For example, to drive with the arrow keys, add use Libraries.Interface.Behaviors.Games.VehicleMovementBehavior at the top, and these lines in CreateGame, after the car is found:

VehicleMovementBehavior driving = car:GetVehicleBehavior()
driving:SetForwardKey(keys:UP)
driving:SetReverseKey(keys:DOWN)
driving:SetLeftKey(keys:LEFT)
driving:SetRightKey(keys:RIGHT)

How the scene builds the car

When the game loads the scene, the car's controller builds it, so the program only finds it and drives it.

  • The body is a box, lower and shorter than the model, so its nose, tail and belly clear slopes. It weighs 800 kilograms, and its turn damping of 0.3 makes 30 percent of its turning speed fade each second.
  • The model rides on the body, at the offset in the Model card, and has no physics of its own.
  • Four wheels hang under the body, each a ray straight down with a spring. The springs sag under the car's weight by 9.8 divided by 4 times the stiffness, whatever the car's mass: about 0.25 at a stiffness of 10. The front two steer, and the engine turns the ones chosen in the Wheels card, the rear two at first.
  • The camera follows the body from behind and above, if Camera follows this is checked.

Why cars tip and skid

When a car turns, its tires pull it sideways, toward the inside of the turn. That pull happens at the ground, but the car's weight is centered higher up, at its center of mass. The higher the center of mass, and the faster the turn, the more that sideways pull tries to roll the car over its outside wheels. What holds it down is its weight, resting on those outside wheels. The farther apart the wheels are, the harder the weight resists tipping.

The car's settings are tuned for this:

  • Wheels out sets how far out to each side the wheels are. A wider stance resists tipping.
  • Roll influence, 0, applies the tires' sideways pull at the height of the body's center instead of at the ground, so turning doesn't roll the car at all. Real cars aren't that lucky; this is one of the places a game makes driving easier than real life.
  • Tire grip, 3, is about three times a real tire's. The more grip, the more suddenly a slide comes when it does.
  • Steering lock, 0.35, keeps the front wheels from turning too sharply, and Steering speed, 3, turns them in over a third of a second instead of at once.
  • Turn damping, 0.3: much more fights the tires in a turn.

Slopes test the body and the springs. A low, short box clears the start and end of a hill, and soft springs let the wheels drop and stay on the ground over a crest. A raycast wheel can't reach past its rest length, so it can drop only as far as the car's weight presses its spring.

Engage

In this activity, you and a partner add the toy car to a scene with a terrain and drive it around. The goal is to get a working vehicle running in your own scene and feel how the physics settings change the way it drives. Use a scene with a terrain that has some hills and valleys, such as one you made in Shaping Terrain or Generating Terrain. Follow Getting the car, Adding the car to the scene and Giving the car a controller, replace Main.quorum with the program on this page, and run it. Take turns driving: one partner drives while the other gives directions, such as drive to the top of the nearest hill, go down into the valley and back up, or make a full circle without tipping over. Press R whenever the car needs a fresh start.

When you've both had a turn, try changing one setting at a time in the Controller section, running the game again after each change and writing down what you notice. For example:

  • halve Engine force, from 3000 to 1500: can the car still climb the same hill?
  • set Wheels out to about two thirds of what it is, or Roll influence to 0.5: does the car tip more easily on sharp turns?
  • set Tire grip to 1, then to 10: what happens to turning and skidding?
  • double Stiffness, from 10 to 20: does the ride over bumps change?
  • in the layer's Physics section, set Gravity y from -9.8 to -1.6, the Moon's: how do hills and bumps change?

Undo each change before trying the next, so you know which change did what.

Wrap up

A game car is a physics simulation built from parts: a heavy body, springs on invisible rays, an engine, steering and tires with limited grip. Many of its numbers were chosen to make driving fun rather than perfectly real, such as a roll influence of 0. Which of the settings you tried made the car feel most realistic, and which made it most fun to drive? When would a game choose fun over realism?