Guide

How to make a three.js game multiplayer

Updated 2026-11-08

Short answer: load Joinable's script, register the game with Joinable.game(), report your player's position from local(), and move one mesh per other player from the list Joinable gives you every frame. Joinable runs invites, quick match, the waiting room, a synced 3-2-1, live standings, results and rematch. No server code.

Which pattern fits

Your gameUse
Racer, flyer, runner with a finishFull rounds, race
Score or time attackFull rounds, score
Exploring a world together, avatarsPattern B (positions sync through a plain state object)

Never sync meshes, scenes or Vector3s: an Object3D leads into the whole scene graph. Report plain numbers, and for Pattern B keep positions in a plain object the scene draws from. Pattern A's guest-side prediction relies on the same requestAnimationFrame wrapper, so on an engine that owns its loop, test Pattern A with two windows before relying on it. race states are 2D (x, y, a); a 3D game reports its ground plane: x and z go in x and y, the heading in a. Keep the state to flat numbers, under 1.5 KB. Height comes from your own world (the track's surface under the car), not from the network.

Full rounds

<script type="module" src="main.js"></script>
<script async src="https://relay.getjoinable.com/sdk.js" data-connect="invite"></script>

No key while you build. On localhost Joinable works without one, free, in rooms of up to 4 players. Before the game goes live on a real site, get a key free at getjoinable.com/app and add data-key="pk_…" to the tag. Set theme to your game's own colours and font too: Joinable's waiting room, countdown and results then look like part of your game (the kit's "Match the game's look").

// main.js
import * as THREE from 'three';

const rivals = new Map();        // player id → mesh
let others = [];                 // the other players, from Joinable's remote() hook
let round = null;                // { rng, started }

function mulberry32(a) {         // small seeded RNG: same seed, same track on every device
  return () => ((a = (a + 0x6d2b79f5) | 0), (((a ^ (a >>> 15)) * (1 | a)) >>> 0) / 4294967296);
}

renderer.setAnimationLoop((t) => {
  const dt = clock.getDelta();
  if (round?.started) drive(player, dt);
  for (const p of others) {
    if (!p.state) continue;                   // no position from them yet
    let m = rivals.get(p.id);
    if (!m) { m = makeKart(new THREE.Color(p.color)); scene.add(m); rivals.set(p.id, m); }
    m.position.set(p.state.x, groundHeight(p.state.x, p.state.y), p.state.y);
    m.rotation.y = -p.state.a;
    m.visible = !p.stale;
  }
  renderer.render(scene, camera);
});

(window.JoinableQ = window.JoinableQ || []).push((Joinable) => {
  playOnlineButton.hidden = false;
  playOnlineButton.onclick = () => Joinable.open();
  Joinable.game({
    profile: 'race',
    name: 'My Racer',
    players: { min: 2, max: 8 },
    theme: { accent: '…', panel: '…', text: '…', font: '…' }, // your game's own colours and font
    public: true,
    start({ seed, players, me }) {
      round = { rng: mulberry32(seed), started: false };
      buildTrack(round.rng);                             // course from the seed only
      placeOnGrid(player, players.findIndex((p) => p.id === me));
    },
    go() { round.started = true; },
    local() {
      if (!round) return null;
      const v = player.velocity;                         // your own THREE.Vector3
      return { x: player.position.x, y: player.position.z,
               a: -player.rotation.y, vx: v.x, vy: v.z, lap: player.lap, progress: player.progress };
    },
    remote(players) { others = players; },               // before every frame
    stop() {
      round = null;
      others = [];
      for (const m of rivals.values()) scene.remove(m);
      rivals.clear();
      showMenu();
    },
  });
});

// when the player finishes:
window.Joinable?.finish({ time: player.raceTime });

Draw the other players from the remote(players) hook. Joinable calls it before each frame of any engine that runs on requestAnimationFrame, as renderer.setAnimationLoop does (checked with three.js 0.170, even when the engine starts before Joinable loads). Keep the list and draw from it in your loop, as above. Reading Joinable.remote() in the loop gives the same list, but the self-test before getjoinable 0.2.3 fails a race game without the hook.

The SDK loads after your module, or not at all; the queue (JoinableQ) handles both, and the game plays solo when Joinable is missing.

Test it

npx getjoinable test http://localhost:5173/ --channel chrome

--channel chrome uses your installed Chrome with its GPU. The bundled headless Chromium draws WebGL in software, and a heavy scene can drop to a few frames a second there.

Where this stops working

Copy the prompt for your coding agent or sign up free