Netcode

Netcode

Fast-paced games can’t wait for the network. If your character only moves after a round-trip to the server, controls feel underwater. But if the client simply moves itself, the server is no longer in charge and cheating becomes trivial.

Colyseus 0.18 gives you both: the server stays authoritative, and the client predicts. Your own movement responds instantly, remote players move smoothly, and a well-aimed shot at a moving target actually lands. No hand-rolled netcode stack required.

Available in Colyseus 0.18+. These APIs (room.input(), Predict, defineInput(), setFixedTimestep(), allowRewindState()) are new in 0.18 and have no equivalent in earlier versions.

The mental model

The stack is one loop split across the server and the client. Each half is configured independently, but they only make sense together:

  • The server runs the authoritative simulation at a fixed tick rate.
  • The client predicts its own entity by running the same step function locally. When the server’s authoritative state arrives, it reconciles: roll back, replay the inputs the server hasn’t processed yet, and smoothly correct any mismatch.
  • Remote entities are smoothed from the server stream (interpolated a little in the past, or dead-reckoned forward).
  • For hits, the server rewinds other entities to where the shooter saw them (their render time). That way, a well-aimed shot at a moving target registers.

One input per fixed step; one predict.tick() per render frame drives everything.

Which primitive for which interaction?

Every interaction in your game maps onto a small set of primitives. Find the row that matches, then jump to the page that documents it:

InteractionPrimitivePage
Your own movement (one entity, flat fields)predict.reconcilerClient Prediction
Anything your inputs push / carry / throw (paddle + puck, vehicle + cargo)predict.sim (composite scalars)Client Prediction
Your movement inside a physics engine (Rapier/crashcat)predict.sim (engine handle)Client Prediction
Remote players you don’t controlPredict lerpClient Prediction
Server-driven ballistics nobody touchesPredict reckonRecipes
Discrete events your timeline produces (a goal, a kill, a pickup)predict.defineEvent + ctx.predictClient Prediction
Projectiles you spawn (predicted → authoritative handoff)predict.spawnsRecipes
Hitscan against others (instantaneous, server-owned target)allowRewindState + rewind.lastSeenByLag Compensation

Read in order

New to prediction? Read top to bottom. Each page builds on the one before it:

Runnable reference

Prefer to learn by poking at something live? The Prediction Playground is an interactive tour of this whole section: twelve small labs, each isolating one concept. Rollback and reconciliation, the interpolation modes, dead reckoning, lag compensation, optimistic events, predicted spawns, composite worlds. Every lab has a live latency slider and visualizations of what the SDK is doing (server ghosts, pending-input chips, rewind markers). Each also shows the exact SDK-facing code it runs. The source is on GitHub.

Premium demos

The playground isolates each concept. These 5 prototypes put them all together: authoritative server, client prediction, smoothed remotes and lag compensation running as one stack. All of them are free to play in your browser.

The set is actively expanding, with new prototypes and with more engine ports of the existing ones. Air Hockey already ships Godot and Unity clients alongside its Three.js build.

Air Hockey, gameplay screenshot
Air Hockey
3D air hockey where everything is predicted: your mallet, the puck, hits and even goals resolve locally and are settled by the server. First to 7 wins.Three.js · Godot · Unity
ColyStrike (FPS), gameplay screenshot
ColyStrike (FPS)
First-person shooter: predicted movement with reconciliation, server-validated hitscan with lag compensation, and a C4 plant and defuse loop.Three.js
MOBA, gameplay screenshot
MOBA
A 3-lane MOBA on a deterministic shared simulation: fixed timestep and client prediction driving heroes, creeps, towers and 5v5 bot matches.Three.js
Platformer, gameplay screenshot
Platformer
2.5D platformer built as a prediction harness: reconciled movement, rideable moving platforms, and stomps and dashes that hold up under lag.Three.js
Colyseus Karts, gameplay screenshot
Colyseus Karts
Kart racing with hold-to-drift mini-turbos, item boxes and rockets: rollback prediction, dead-reckoned projectiles, and rewind-based hit checks.Three.js

The source code is the sponsor-only part: these repositories are private, available to Colyseus sponsors.

Become a sponsor for the source code

Coming from the manual approach? The Phaser tutorial builds prediction, interpolation, and a fixed tick rate by hand to teach the concepts. This section documents the built-in 0.18 API that does the same work for you.