IN THIS ARTICLE
Subscribe to Our Newsletter
Connectivity puts the ‘multi’ in multiplayer gaming. When building out a multiplayer game, any aspect of the game that involves communication between two or more players, whether it be in-game chat or sync player position, requires a reliable and consistent connection between the users.
Any player that has experienced lag knows exactly what I’m talking about here. As a developer, how can can you ensure stable and secure connectivity for core multiplayer features?
In this blog post, we’ll walk you through some different aspects of multiplayer game dev that require a reliable realtime connection for a smooth player experience, and I’ll link you to specific, full PubNub tutorials and demos we’ve written for each one. We’ll take a look at:
- Syncing player position and actions
- In-game chat
- Realtime Statistics
Managing Player Position
Managing and syncing player position is a key element of multiplayer gaming. If a player swings his sword and moves, those actions need to be reflected in realtime on every other players’ screen. In multiplayer game dev, this is known as lockstep, where the actions of all players sync in realtime.
A simple method for managing multiplayer interaction would be to send the entire state of the world to every other user whenever an action takes place. However, this requires a heavy load, and makes the game sluggish and laggy. Instead, we can simply send an "add or remove" command to a common channel every time a user carries out an action. For more details on how to handle multiplayer lockstep, we have a multiplayer interaction tutorial and demo available here.
For lightweight games, multiplayer functionality and lockstep can be implemented fairly easily. Our blog post Lightweight Multiplayer HTML5 Games with melonJS gives a good overview of multiplayer support and communications. It includes a live demo, so open up two browser windows in incognito mode to check out the lockstep in action! If you happen to be a voxel.js developer (or a fan of Minecraft), we also wrote a DIY multiplayer Minecraft tutorial and demo, which covers similar territory.
For a large majority of multiplayer games, you need a way for users to seamlessly communicate with one another, and in-game text chat does just that. Basic text messaging is the core of in-game multiplayer communication, and especially for fast-paced multiplayer games, you need realtime speed and low latency communication. For a simple chat application, check out our tutorial and demo on building multiplayer realtime chat.
Once you have your core chat application, enabling users to send and receive messages, you can start adding features tailored to your game. For example, you may want Presence functionality, which allows users to see who is online and offline, or Storage & Playback, which stores and retrieves previous chat messages.
General multiplayer group messaging is one thing, but what if you want to enable users to privately request and send messages to other users? Building private chat into your multiplayer application is another great feature that you can build with PubNub. We have a private chat tutorial that shows you how to create private chat, send alert and request popups, and give you fine-grain control over access to channels within users' chat.
I don’t know about you guys, but I love statistics. And I love realtime, live-updating statistics even more. To build realtime updating statistics into your multiplayer game, you need to do two things. You need to modify your source code, then build a simple, scalable server infrastructure to serve the realtime statistics.
With thousands (or maybe even millions of users) out there, how the heck are you going to link them all up to play against one another? Will you match users randomly? Or, maybe you'd like to match them based on skill? Or, do you want to allow them to challenge one another?
How about all three?
Game Server to Manage State of Games and Players
When building out a game server, a common issue is managing the state of games and players together, and communicating those states to users, no matter what their platform is. A C# game server is a great way to start, and when combined with PubNub and a REST-esque model, you have yourself the start of a simple, scalable game server. You’ll need two primary units, a server and a game manager. To get started, check out our tutorial on building a C# game server.
PubNub makes it easy to build and scale multiplayer game features and functionality. Whether you’re using PubNub to power your in-game chat communication layer, or syncing player actions, PubNub ensures that your game will have the realtime speed and reliability you need to present a smooth player experience.