How to make a racing game multiplayer
Updated 2026-11-23
Short answer: in an online racing game, each player's device runs the real game and simulates only its own car. It sends that car's position and velocity about 20 times a second, and draws every rival where it is now, predicted from its last update. Bumps are shared: each device pushes only its own car, by half. With Joinable you get this, plus invites, quick match, a shared 3-2-1, live positions, one podium and rematch, from one async script tag and one Joinable.game({ profile: 'race' }) call. No server code.
Two live kart and rally games run on it today: Turbo Rally and Sky Isle Karts on etheria.games.
Why racing netcode is different
A racer can't wait for a server to approve every frame: your own car has to answer the stick at once, at 60 frames a second, on a phone on 4G. So the usual model for online racers is:
- Your car is yours. Your device runs its physics, with no input delay.
- Rivals are predicted. Their updates arrive a little late, so your device moves each one on from its last known position by its velocity, along the turn it was making, to where it should be now. When a new update disagrees, the car eases onto it over about 120 ms instead of jumping.
- Everyone starts together. A shared clock and a shared seed give every device the same track, the same weather and the same "go".
Joinable's race profile does all three. The more general picture, and how it compares with lockstep and shared worlds, is in netcode for web games.
The code
Load the script async, so the game starts at once even if Joinable can't load, and with data-connect="invite", so solo players never connect:
<script async src="https://relay.getjoinable.com/sdk.js" data-connect="invite"></script>
No key is needed on localhost. Before going live, get one free at getjoinable.com/app and add data-key="pk_…".
(window.JoinableQ = window.JoinableQ || []).push((Joinable) => {
onlineButton.hidden = false; // offer online play only once Joinable is here
Joinable.game({
profile: 'race',
name: 'Kart Loop',
players: { min: 2, max: 8 },
public: true, // strangers can meet through Quick match
options: {
laps: { label: 'Laps', choices: [1, 2, 3], default: 2 },
},
start({ seed, options, players }) { buildTrack(seed); placeOnGrid(players); },
go() { racing = true; },
local() { return { x: car.x, y: car.y, a: car.a, vx: car.vx, vy: car.vy, lap, progress }; },
remote(players) { for (const p of players) if (p.state) drawRival(p); },
stop() { showMenu(); },
});
});
// when your car crosses the line:
window.Joinable?.finish({ time: 83.42 });
local() returns flat numbers. Include vx and vy: prediction uses them. progress is laps done as a fraction (1.37), which keeps the live positions the same on every screen. Everything random that changes the course must come from seed.
Kart Loop is a complete example: invite, countdown, bumps and podium. Engine guides: plain canvas, three.js, Phaser, Babylon.js.
Bumping: real contact, split fairly
Cars that pass through each other feel like ghosts. Real contact needs one rule: draw and collide with the rival in the same place, and each device does half.
Each entry in remote(players) has a state (where the rival is now) and a contact factor from 0 to 1. In your own physics:
- Treat each rival as a solid body at
p.state, the place you draw it. - On contact, move only your own car, by half the overlap, and apply half the bounce to your own velocity, scaled by
p.contact. The rival's device does the other half. - Never move the rival. Play the hit once per contact, not every frame.
We learned this the hard way on Turbo Rally. The first version drew rivals 100 ms in the past but collided with a predicted "now", so at speed the car you saw and the car you hit were a car length apart. And both phones applied the whole push, so every bump counted twice. Fixing both cut the worst on-screen jump of a rival car from 52 to 7 (test/glitch.mjs, two players with 120 ± 40 ms of added lag).
Latency, said plainly
Two phones agree on a bump only as well as their predictions agree.
| Round trip between players | What contact feels like | What Joinable does |
|---|---|---|
| Under ~120 ms | Solid, like local play | Full bumps |
| ~120–250 ms | Small disagreements | Softer bumps as ping rises |
| Over ~250 ms | Contact can't be fair | Rivals still race but pass through, drawn translucent |
Racing at these distances still works; only contact changes. Prediction along the turn keeps rivals steady: at 300 ± 100 ms of added delay, a rival's typical jerk on screen went from 0.66 to 0.26–0.28, against 0.23 on a perfect connection.
Items, AI racers and a full grid
- Items (shells, bananas, boosts) travel as your own messages with
Joinable.send. The thrower says what was thrown, and each device decides hits on its own kart. The kit has the recipe. - AI racers: with
bots: true, the host can fill empty seats with your game's own AI karts. The host's device drives them and everyone else sees them inremote(players). WithaiAfter: 20, a quick-match player races the AI after 20 seconds if nobody else comes. - Picks:
playerOptionslets each player choose a car in the waiting room, with pictures. - Your look: pass
themewith your game's colours and font, and Joinable's waiting room, countdown and results look like part of your game.
Test it
npx getjoinable test http://localhost:5173/
The self-test opens headless players (--players 3 to 8), checks they get the same seed, see each other, reach one result and start a rematch. Give Joinable.game a testDrive() that turns on your autopilot, and the test players race to the finish. Then race one real round on two devices on different networks.
Or skip the wiring: paste the prompt into your coding agent. It reads the agent kit, wires the hooks and runs the self-test.
FAQ
Do I need a server for a multiplayer racing game?
No. Joinable's hosted relay runs the rooms, invites, quick match, the shared clock and the results. Each player's device runs your game and its own car's physics; your code never opens a WebSocket.
How many players can race in one room?
Up to 4 on the free Sandbox plan on a live site, 8 on Starter and Pro, and 16 on Studio. On localhost, rooms hold 8 on every plan, so you can test a full grid before paying. AI seats don't count as players.
Will cars bump into each other online?
Yes. Each device treats rivals as solid bodies at the position it draws them, and pushes only its own car by half. Bumps soften as ping rises, and above about 250 ms round trip rivals pass through, because contact can't be fair at that distance.
Can players cheat in an online race?
Each device reports its own finish time. The room rejects impossible times, which is fine for friends and casual leaderboards. Ranked play with prizes needs a server that runs the race itself, which Joinable doesn't offer yet.
Does it work with a 3D racer?
Yes, if it runs in a browser page: three.js, Babylon.js and PlayCanvas racers work the same way. Joinable sends positions and velocities, never your meshes or textures.