Real-Time Gaming Blog

Simple 3D Multiplayer Game in the Browser

3 min read Joe 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

Top Trends to Engage Your App Users
InsightsSep 27, 20224 min read

Top Trends to Engage Your App Users

Take a look at the top trends that are the most effective in attracting customers and reducing churn, and how you can incorporate...

PubNub Staff

PubNub Staff

Comparing Game Engines: Unity vs Unreal vs the Rest
Real-Time Gaming BlogSep 21, 20225 min read

Comparing Game Engines: Unity vs Unreal vs the Rest

Comparing the major game engines: Unity vs Unreal Engine vs Corona SDK vs GameMaker Studio, including the benefits and cons of...

PubNub Staff

PubNub Staff

Python Socket Programming: Client, Server and Peer Libraries
BuildSep 21, 20226 min read

Python Socket Programming: Client, Server and Peer Libraries

Sockets (aka socket programming) enable programs to send and receive data, bi-directionally, at any given moment. This tutorial...

PubNub Staff

PubNub Staff