Skip to content

Vehicle driving

capstone lesson Intermediate ⏱ 15 min vgai 0.1.0

Prerequisites: Foundations · Manual — Physics

What you'll learn

  • Run the vehicle example and drive it
  • Understand the Rapier raycast vehicle controller and suspension
  • See smooth steering and dynamic obstacles

What you'll build: A drivable vehicle with suspension, steering, ramps, and knockable obstacles.

Walkthrough — Vehicle driving · generated by site/media/lessons/capstones-batch.lesson.ts (5 steps)

The vehicle example (packages/editor/template/src/examples/vehicle/) uses a Rapier DynamicRayCastVehicleController with 4-wheel suspension, front-wheel drive, smooth steering, ramps, and dynamic obstacles to knock around.

  1. Open the vehicle scene. Load examples/scenes/vehicle.vscn.json.

    The vehicle scene loaded
    The vehicle course.
  2. Enter play mode. Press Play.

    The vehicle running in play mode
    Play mode.
  3. Accelerate with W. Drive forward; S reverses and Space brakes.

    The vehicle driving forward
    Front-wheel drive via the raycast vehicle controller.
  4. Steer with A and D. Steering is smoothed for a natural feel; hit the ramps and knock the dynamic obstacles around.

    The vehicle steering
    Smooth steering + dynamic obstacles.
  5. Stop play mode. Press Stop (or Escape).

Gameplay lives in GameComponents declared in the scene file (VehicleController, ChaseCamera). The controller wraps Rapier’s raycast vehicle — each wheel raycasts to the ground for suspension, drive torque goes to the front wheels, and steering is eased toward the input. The chase camera follows from behind. Audio, HUD, and a reference grid are attached in setup().

Recap

New functionality

  • Ran and drove the vehicle
  • Used the ramps and hit obstacles

New concepts & skills

  • A DynamicRayCastVehicleController models wheels via rays + suspension
  • Drive/steer/brake come from input actions
  • Chase camera + gameplay are GameComponents

Next lesson → Capstone: RTS