Real-Time Gaming Blog

Peer-to-Peer Lockstep for Multiplayer Communication

2 min readJoe Hanson on Dec 9, 2014
Try PubNub Today

Free up to 1MM monthly messages. No credit card required.

Subscribe to our newsletter

By submitting this form, you are agreeing to our Terms and Conditions and Privacy Policy.

Robot Onslaught is a multiplayer game that uses PubNub to power and sync all peer-to-peer lockstep to ensure accurate, real-time player position.


We’ve updated our SDKs, and this code is now deprecated.

Good news is we’ve written a comprehensive guide to building a multiplayer game. Check it out!

In our Multiplayer Game App Challenge, full stack developer Thomas Hunter built Robot Onslaught, a twin-stick multiplayer robot-shooting game.

Robot Onslaught used a number of different technologies to run entirely serverless, with PubNub sitting as the network transport layer, to ensure reliable and consistent peer-to-peer lockstep for user position. PubNub keeps data synchronized between the two (or any number of) clients.

peer-to-peer lockstep

We say, cool! Robot Onslaught is a great use case for where PubNub sits in multiplayer game development and communications. Let’s get to the action. You can play Robot Onslaught here. Open two browsers and shoot yourself, or force a friend to play with you and shoot your friend. Either way works.

You can also check out the full GitHub repo here, and we recommend also taking a look at, a game engine for HTML5 games.

Multiplayer Peer-to-Peer Lockstep Communication with PubNub

In the simplest terms, when a user say moves their player on the screen, that player’s movement needs to be reflected in real time across every other user’s screen. So how do we do that?

You need to pass movements back and forth over PubNub through a private channel unique to each game, and animate those moves received from the remote opponent(s). One might think that the best way to do this is to send the entire state of the world to every other user whenever a state changes (ie. a user takes an action).

This is a recipe for lag. Instead, using PubNub, you can simply send an add/remove command to a channel everytime a user carries out an action. We have a multiplayer peer-to-peer lockstep tutorial and demo available here.

Robot Onslaught Video Demo

More from PubNub

Can Empathy Exist in the Metaverse
News May 16, 20221 min read

Can Empathy Exist in the Metaverse

A roundtable discussion led by PubNub’s COO, Casey Clegg, exploring the topics of what it means to be human in a virtual world.

PubNub Staff

PubNub Staff

How to Advance Telehealth and Virtual Care Technologies
News May 2, 20221 min read

How to Advance Telehealth and Virtual Care Technologies

Dr. Joe Kvedar, Chair of the Board for the American Telemedicine Association, joins our COO, Casey Clegg, to discuss why...

PubNub Staff

PubNub Staff

Another Step Towards Data Security: ISO-27001 Implementation
BuildMay 2, 20221 min read

Another Step Towards Data Security: ISO-27001 Implementation

Today, we are glad to announce that we are currently in the process of implementing ISO-27001 security standards.

PubNub Staff

PubNub Staff