Skip to content

First-person shooter

capstone lesson Intermediate ⏱ 15 min vgai 0.1.0

Prerequisites: Foundations · Manual — Input (pointer lock), Physics

What you'll learn

  • Run the FPS example and capture the pointer for mouse look
  • Understand how pointer-lock mouse look drives the first-person camera
  • Throw dynamic physics balls and knock around crates

What you'll build: A playable first-person shooter with pointer-lock look and throwable physics balls.

Walkthrough — First-person shooter · generated by site/media/lessons/capstones-batch.lesson.ts (5 steps)

The fps example (packages/editor/template/src/examples/fps/) is a pointer-lock first-person shooter: WASD movement, jumping, and throwable physics balls with a hold-to-charge mechanic, plus pushable crates.

  1. Open the FPS scene. Load examples/scenes/fps.vscn.json.

    The FPS scene loaded
    The FPS arena.
  2. Enter play mode. Press Play to boot the runtime.

    The FPS running in play mode
    Play mode.
  3. Click to lock the pointer and look around. Clicking the canvas requests pointer lock; mouse movement then drives the first-person camera. (Esc releases the pointer.)

    First-person view after pointer lock
    Pointer-lock mouse look.
  4. Throw a ball with a click. A click throws a dynamic physics ball (hold to charge for more power); balls collide with and knock around the crates.

    A thrown physics ball in the arena
    Throwable dynamic physics.
  5. Stop play mode. Press Stop (or Escape) to return to editing.

Movement and camera live in GameComponents declared in the scene file (FPSController, FPSCamera). The ball pool, hold-to-charge/throw logic, audio, and HUD are wired in the example’s setup() as runtime infrastructure, finding the player via queryByComponent.

Recap

New functionality

  • Ran the FPS and captured the pointer
  • Looked around in first person
  • Threw physics balls and hit crates

New concepts & skills

  • Pointer lock + mouse delta drive a first-person camera
  • Throwables are dynamic Rapier bodies
  • Player movement/camera are GameComponents; spawning is setup infrastructure

Next lesson → Capstone: Vehicle