Skip to content

Multiplayer: third-person tag arena

capstone lesson Advanced ⏱ 25 min vgai 0.1.0

Prerequisites: Manual β€” Networking Β· Multiplayer β€” Colyseus rooms Β· Capstone β€” shared-physics playground

What you'll learn

  • Connect to a Colyseus room through a real lobby flow
  • Understand a server-driven match loop (lobby β†’ countdown β†’ playing β†’ scoreboard)
  • See how tagging and AI bots are server-authoritative

What you'll build: A multiplayer tag arena with a lobby, game phases, and server-controlled AI bots on a Colyseus room.

Walkthrough β€” Multiplayer: third-person tag arena Β· generated by site/media/lessons/tierc-mp-batch.lesson.ts (5 steps)

The arena is a full multiplayer game, not just a synced scene: a connect screen, a lobby, a server-driven match loop, and AI bots β€” all owned by ArenaRoom. This capstone walks the connection flow you can capture reliably, then explains the match loop from the server code.

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

    The arena scene loaded in the editor
    The tag arena, ready to run.
  2. Enter play mode β€” the example shows a connect screen. Name, player color, bot count, and the server URL (ws://127.0.0.1:2567). The menu lives in phase-overlay.tsx.

    The arena connect screen
    The connect form: name, color, bot count, server URL.
  3. Click Join Game β€” the client joins the arena room. network.ts opens the room and the UI advances to the lobby phase.

    The connected lobby with bots
    Connected: the lobby reads server state (+ 2 bots) and shows the host's Start Game.
  4. The lobby reflects server state. The + 2 bots line and the Start Game button are driven by the room: bots are server-spawned NPCs, and the button renders only for the host (view.isHost). Pressing it sends start_game, moving the room to the countdown.

    The lobby reflecting server state
    Server-driven lobby: spawned bots and host-only controls.
  5. Stop play mode. Press Stop (or Escape) β€” the room connection closes.

Recap

New functionality

  • Connected to a Colyseus room through a real lobby flow
  • Read server-driven lobby state (spawned bots, host controls)

New concepts & skills

  • A multiplayer game is a phase machine: lobby β†’ countdown β†’ playing β†’ scoreboard
  • start_game is host-gated and phase-gated on the server
  • Tagging and AI bots are server-authoritative; clients send input and render state

Next lesson β†’ Multiplayer: tank arena