IN THIS ARTICLE

    Good News

    Good News! We’ve launched an all new Chat Resource Center.

    We recommend checking out our new Chat Resource Center, which includes overviews, tutorials, and design patterns for building and deploying mobile and web chat.

    Take me to the Chat Resource Center →

    Warning

    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!

    Connectivity puts the ‘multi’ in multiplayer gaming. When building out a multiplayer game, any aspect of the game that involves communication between two players, whether it be in-game chat or sync player position, requires a reliable and consistent connection between the users.

    Any of us gamers that have experienced the dreaded ‘lag,’ know exactly what I’m talking about here. How can can you ensure stable and secure connectivity for multiplayer game core engine and features?

    In this blog post, we’ll walk you through some different aspects of multiplayer game dev that require a reliable realtime connection for gaming, and I’ll link you to specific full PubNub tutorials and demos we’ve written just for this. We’ll take a look at:

    • Syncing player position and actions
    • In-game chat
    • Matchmaking
    • Realtime Statistics

    Managing Player Position

    Managing and syncing player position is a key element of multiplayer gaming. If say a player swings his sword and moves, that action needs 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 are sync in realtime, like they’re happening in real life.

    A common 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 every time to a common channel every time a user carries out an action. 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, and open it up in a couple browsers 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 Minecraft tutorial and demo.

    Realtime Elements Every Multiplayer Game Dev Needs

    In-game Chat

    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 chat speed and latency. For a simple chat application, check out our tutorial on 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 multiplayer game dev. For example, you may want Presence functionality, allowing 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 additional chat feature. We have a private chat tutorial that shows you how to create private chat, send alert and request popups, and give you fine grain access over users chat.

    Multiplayer Statistics

    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.

    For large scale multiplayer games, you’ll have a high load of data needing to be delivered in realtime. As a result, building out and implementing a stats server is where you need to start. Luckily for you, we have a full tutorial and demo on building out a realtime statistics delivery system with JavaScript and Python!

    Matchmaking

    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 based on skill? Or do you want to allow them to challenge one another?

    How about all three?

    You need to start with a matchmaking algorithm and this can be achieved fairly easily with JavaScript. We have tutorials for all three options: random matchmaking, skill-based matchmaking, and user challenge matchmaking.

    Game Server to Manage State of Games and Players

    When building out a game server, a common issue is how you will manage the state of games and players, and communication 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 a simple, scalable game server. You’ll need two primary units, a server and a game manager. Check out our tutorial on building a C# game server.

    Wrapping Up Multiplayer Game Dev

    PubNub makes it easy to build and scale multiplayer game dev features and functionality. Whether you’re using PubNub to power your in-game chat communication layer or syncing player actions, PubNub ensures that gamers will get the speed and reliability of realtime that they want.

    Try PubNub today!

    Build realtime applications that perform reliably and securely, at global scale.
    Try Our APIs
    Try PubNub today!
    More From PubNub