Guide

How to make a PlayCanvas game multiplayer

Updated 2026-11-08

Short answer: add Joinable's script to the project as an external script, and register the game from a script component with Joinable.game(). The component reports your player and moves one entity per other player in its update. Joinable runs invites, quick match, the waiting room, a 3-2-1, results and rematch.

Adding the SDK

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").

A loader that works in the Editor today, as the first script in the project's loading order:

// joinable-loader.js
const s = document.createElement('script');
s.async = true;
s.src = 'https://relay.getjoinable.com/sdk.js';
// s.dataset.key = 'pk_…';   // add your key before the game goes live; localhost needs none
s.dataset.connect = 'invite';
document.head.appendChild(s);

The script component

// joinable-race.js: attach to a "Game" entity
const JoinableRace = pc.createScript('joinableRace');
JoinableRace.attributes.add('kart', { type: 'entity' });
JoinableRace.attributes.add('rivalTemplate', { type: 'asset', assetType: 'template' });

JoinableRace.prototype.initialize = function () {
  this.rivals = new Map();
  this.others = [];                                        // the other players, from the remote() hook
  (window.JoinableQ = window.JoinableQ || []).push((Joinable) => {
    this.app.fire('joinable:ready');                       // show your "Play online" button
    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 }) => this.app.fire('race:start', seed), // your race script resets from the seed
      go: () => this.app.fire('race:go'),
      local: () => {
        const p = this.kart.getPosition(), v = this.kart.script.kart.velocity;
        return { x: p.x, y: p.z, a: this.kart.getEulerAngles().y * pc.math.DEG_TO_RAD, vx: v.x, vy: v.z,
                 lap: this.kart.script.kart.lap, progress: this.kart.script.kart.progress };
      },
      remote: (players) => { this.others = players; },    // before every frame
      stop: () => { this.others = []; this.clearRivals(); this.app.fire('race:menu'); },
    });
  });
};

JoinableRace.prototype.update = function () {
  // PlayCanvas's loop runs on requestAnimationFrame, so remote() has filled this.others for this
  // frame (checked with PlayCanvas 2.3).
  for (const p of this.others) {
    if (!p.state) continue;                   // no position from them yet
    let e = this.rivals.get(p.id);
    if (!e) { e = this.rivalTemplate.resource.instantiate(); this.app.root.addChild(e); this.rivals.set(p.id, e); }
    e.setPosition(p.state.x, 0, p.state.y);
    e.setEulerAngles(0, p.state.a * pc.math.RAD_TO_DEG, 0);
    e.enabled = !p.stale;
  }
};

JoinableRace.prototype.clearRivals = function () {
  for (const e of this.rivals.values()) e.destroy();
  this.rivals.clear();
};

Elsewhere: the "Play online" button calls window.Joinable?.open(), and the race script calls window.Joinable?.finish({ time }) at the line.

Check the sign of the angle against your scene: PlayCanvas's Y rotation and Math.atan2 on the ground plane can run in opposite directions.

Test it

npx getjoinable test https://launch.playcanvas.com/… --channel chrome

Launch URLs need the key to allow launch.playcanvas.com; a local build on localhost is simpler.

Copy the prompt for your coding agent or sign up free