Real-Time Gaming Blog

Simple 3D Multiplayer Game in the Browser

3 min readJoe Hanson on Sep 23, 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.

Code and demo for building a simple, 3D multiplayer real-time chess game in the browser that syncs player position across multiple devices.


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 last month’s PubNub 3D Visualization Challenge, winner Robert Oschler built a fun and fast multiplayer 3D chess game with online lobby chat using PubNub Data Streams. In this blog post, Robert gives an overview of his project, 3D multiplayer source code.

In the video below, Robert gives an overview of his application and explains how he incorporated a number of PubNub real-time features into his application.

3D Multiplayer Chess Game

My application is targeted to any chess player with a browser and runs in any WebKit enabled browser, although currently it works best in Chrome.

When I found out PubNub was an ultra-fast, super smooth, messaging network that could be used to create collaborative apps, I realized I needed to get to know the service. I had previously been looking at collaborative technologies like SignalR, etc., but the thought of setting up servers myself, especially those that could scale rapidly under heavy traffic loads, was more than I could handle.

When I discovered that PubNub was an affordable, feature-rich messaging and signaling solution that was “no assembly required”, I decided to go through PubNub’s extensive MemeWarz mutliplayer game tutorial series and see how much effort was involved in programming around it. I was delighted to find out it was extremely easy.

I then searched for a game that I could tie into the chat lobby I had built from the MemeWarz tutorials. I found the 3D Hartwig Chess set project on GitHub and forked it. That project provides an attractive 3D chess set with several really nice animations for moving pieces.

Tying it into PubNub was easy and fun. It became a simple matter of passing the chess moves back and forth over PubNub through a private channel dynamically created for each game, and animating moves received from the remote opponent.

Managing Players with PubNub Presence

The best part was learning about features like the PubNub Presence API, which I used to add and remove users as they join the chatroom, and detect the arrival and exit of an opponent during the game. Implementing that API was equally easy and the idea that I could completely offload the management of online users to PubNub was wonderful. This opens the very real option to create collaborative apps that require no server component yet have all the advantages and features of client apps supported by a heavyweight server!

I look forward to trying out the other powerful PubNub APIs like the Access Management API and the Data Sync API.

3D Multiplayer Game Additional Resources

To DIY, you’ll first need to sign up for a PubNub account. Once you sign up, you can get your unique PubNub keys in the PubNub Developer Portal. Once you have, clone the GitHub repository, and enter your unique PubNub keys on the PubNub initialization, for example:

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