Guide

How to make an RTS or tower defence game multiplayer

Updated 2026-11-23

Short answer: use deterministic lockstep. A strategy game has far too much state to send (hundreds of units, projectiles, fog, economy), so only the players' orders travel, and every device runs the same simulation from the same seed, one fixed tick at a time. It works if your simulation is deterministic: seeded randomness, no clock, fixed iteration order and maths that gives the same answer in every browser. Joinable's lockstep profile carries the orders, drives the ticks, checks every second that all devices still agree, and runs the waiting room, teams, AI seats and results. Firestorm, a real RTS, ran a 4 v 4 battle on it for 10,160 ticks with 0 differences.

Why lockstep, not state sync

A racer can send each car's position 20 times a second. An RTS can't send hundreds of units that often. But orders are tiny: "these 12 tanks: attack building 340" is a few dozen bytes. If every device applies the same orders on the same tick to the same starting battle, every device computes the same battle. Neither is "the server"; both are the battle.

What you get:

The trade-offs: the whole simulation must be deterministic, and every device simulates the whole battle, so a cheater with developer tools could see through the fog of war.

Does your game fit?

Check all six before starting:

  1. The simulation can run without the screen. Logic is separate from drawing, or can be.
  2. Every random number comes from one seeded generator. Cosmetic effects may still use Math.random().
  3. The simulation never reads the clock. No Date.now(), performance.now() or frame delta: whole fixed ticks only.
  4. Player actions can become data, applied in one place.
  5. Iteration order is fixed: arrays or sorted ids, not Sets or Maps filled in network order.
  6. The maths gives the same answer in every browser. + − × ÷, Math.sqrt, floor, round, abs, min, max and imul do. Math.sin, cos, tan, atan2, hypot, exp, log, pow and ** may not: Chrome and Safari can differ in the last digit, and a battle feeds each result into the next tick. Write Math.hypot(x, y) as Math.sqrt(x * x + y * y) and use a lookup table for sin and cos inside the simulation.

Rule 6 came from Firestorm's play-test: Chrome against Safari went out of sync at tick 2412, with no orders anywhere near it. The cause was Math.hypot, sin, cos and atan2 in the simulation.

The code

(window.JoinableQ = window.JoinableQ || []).push((Joinable) => {
  Joinable.game({
    profile: 'lockstep',
    name: 'Tiny Front',
    build: 'tiny-front-1',        // bump when the simulation changes: other builds never meet
    players: { min: 2, max: 8 },
    tick: 50,                     // ms per simulation step
    start({ seed, options, players, me }) { buildBattle(seed, players, me); },
    step(commands, { tick, away, ai }) {
      for (const { player, cmd } of commands) apply(player, cmd);
      runOneTick();
    },
    hash() { return fingerprint(); },  // one number from ids, positions, health, money
    testCommand(rng) { return randomValidOrderForMe(rng); },
    stop() { showMenu(); },
  });
});

// The UI no longer applies orders. It sends them; they run on every device in step().
Joinable.command({ t: 'move', ids: [12, 14], x: 340, y: 220 });

// When the battle ends (every device sees it on the same tick):
window.Joinable?.finish({ place: iWon ? 1 : 2 });

Online, stop your own simulation loop and keep drawing: step() is the only place the battle advances. No pause or speed-up online. Load the script async with data-connect="invite", as in every guide. Tiny Front is the reference RTS: its online.js marks every Joinable line.

What Joinable handles

What Firestorm showed

Firestorm is NOJU's real-time strategy game: armies, bases, production queues, generals' powers and a computer opponent. A coding agent with only Joinable's public prompt, guide and the Tiny Front demo made it a two-player lockstep game in about 66 minutes: 9 files, 357 lines added.

Then 4 v 4: 8 headless clients with AI on every side ran 10,160 ticks, compared 71,120 fingerprints with 0 differences, and produced one result in 9.1 minutes. What broke along the way is in what we learned. You can play Firestorm on etheria.games.

Tower defence and auto-battlers

The same rules apply. In a co-op tower defence, placing a tower is an order and waves come from the seed. Auto-battlers are often simpler still: orders come only between rounds.

Test it

npx getjoinable@latest test http://localhost:5173/

The self-test plays the battle on Chromium and WebKit (Safari's engine) with random orders from testCommand, compares fingerprints tick by tick, and names what isn't deterministic: Math.random() or clock calls inside step() with file and line, and browser-dependent maths. It needs WebKit once: npx playwright-core install webkit. Can't run npx? Open the game with ?joinable-check in two windows for the same checks in a panel.

Or paste the prompt into your coding agent.

FAQ

What is deterministic lockstep?

Every device runs the same game simulation from the same seed, applying the same player orders on the same fixed ticks, so they all compute the same result. Only the orders travel over the network, which is why it suits strategy games with hundreds of units.

Why did my lockstep game desync between Chrome and Safari?

Usually maths. Math.sin, cos, atan2, hypot, pow and similar may round differently in the last digit in different browser engines, and the error grows tick after tick. Use Math.sqrt with multiplication, and lookup tables for angles, inside the simulation.

How many players can a lockstep battle have?

Joinable's lockstep is tested at 8 players, 4 against 4, with AI seats. Rooms hold 4 on the free Sandbox plan on a live site, 8 on Starter and Pro, and 16 on Studio; on localhost they hold 8 on every plan.

Can players cheat in a lockstep RTS?

Every device simulates the whole battle, so a cheater with developer tools could reveal the fog of war. That's acceptable between friends. Ranked play would need a server that runs the battle and shows each player only what they can see, which Joinable doesn't offer yet.

Does it work with Phaser or three.js?

Yes, as long as the simulation runs outside the engine's frame loop. Keep units in plain data that step() updates, and let the engine only draw. Don't use Phaser's Arcade physics for the simulation online: its timing follows the frame rate.

Copy the prompt for your coding agent or sign up free