BACK Contact Us

How do multiplayer games work? From simple to complex

person

Volodymyr Tsaruk

Unity Developer

Contact:

person
person

Volodymyr Tsaruk

Unity Developer

Contact:

person

In this article, we will talk about the importance of multiplayer in games, types of multiplayer, and experience of N-iX Game & VR Studio, eventually delving into a bit more advanced concepts, explaining how modern online multiplayer games work. We’ll uncover how today’s FPS games have managed to eliminate lagging and create immersive, real-time experiences for players worldwide… or at least to create an illusion of it.

Anyway, if you want to know how to make a multiplayer game and/or are interested in finding out more about how multiplayer works, this read is for you:

Why multiplayer is important in modern game dev

First things first, why is multiplayer important in modern games? No, this paragraph won’t be about multiplayer taking over the world and turning the single-player segment to ashes. According to MIDiA Research, 57% of players still prefer solo gaming experiences. The other part of players either prefer multiplayer or don’t care so much at all. However, this preference for single-player gaming remains fairly steady only across the age group of 35+. The real game-changer is among younger players under 35, who are showing a growing inclination toward multiplayer gaming experiences. 

The thing is, games are becoming more and more about social playgrounds. Cooperative games provide opportunities for social interaction, self-expression, and digital coexistence with peers, offering a new dimension to the gaming experience that complements the traditional escapist allure of single-player adventures. This is especially true for our post-COVID world. So rather than dominating the industry, multiplayer games are carving out their own space by catering to a distinct set of needs. 

What exactly is multiplayer?

Before venturing forth, let’s clarify what multiplayer truly entails. To the average player, who may be distant from game development, multiplayer simply means two or more individuals sharing a single virtual world. However, for a programmer well-versed in the intricacies of client data synchronization, multiplayer often presents a complex challenge.

Imagine the game as a series of turns, and each turn consists of a set of commands. These commands guide the game’s progress: move a unit, attack another unit, build a structure, and so on. The trick to making this work in a multiplayer setting is to ensure that every player’s machine processes the exact same set of commands and turns, starting from a common initial state.

What kinds of multiplayer are there?

Split/Shared screen multiplayer:

  • In split/shared screen multiplayer, you and your friends play on the same device, like a TV or a computer monitor.
  • The screen is divided into multiple sections, each showing the perspective of a different player.
  • Each player typically uses a separate controller or input device to control their character.
  • The game’s software manages all players’ actions on the same device.

Local multiplayer:

  • Local multiplayer involves multiple players on different devices but within the same physical location, like players on separate computers or consoles in the same room.
  • These devices are connected either through a local network (like Wi-Fi) or by directly connecting them with cables (like Ethernet or HDMI cables).
  • The game’s software coordinates the actions of all players and ensures they can interact with each other within the game world.

Online multiplayer:

  • Online multiplayer allows players from anywhere in the world to connect and play together over the internet.
  • Players use their own devices and connect to a central server hosted by the game developer, a third-party provider, or even one of the players.
  • The server manages the game world and synchronizes the actions of all players.
  • Data, like player positions, actions, and chat messages, is constantly sent between players and the server to keep the game world consistent for everyone.
  • Players may communicate with each other through text or voice chat, and they can often play with people they don’t know personally.

In this article, we will talk only about local (LAN) multiplayer and online multiplayer, shedding light on the remarkable ingenuity of engineers in seamlessly synchronizing the separate gaming experiences of multiple players into a unified and harmonious whole.

Peer-to-peer

Back when online multiplayer gaming was just finding its feet, games relied on a network setup known as “peer-to-peer” or P2P. In this setup, players connect directly to each other’s devices (peer-to-peer) to play a game, without the need for a centralized server. Each player’s device acts both as a client and a server, allowing players to interact with each other in real time.

This model is still alive and kicking, especially in real-time strategy (RTS) games. Let’s dive into the basics of how it operates: 

Player connection: In a P2P game, players typically connect to each other’s devices directly over a local network (such as a LAN party) or, in some cases, over the internet. They can do this through their IP addresses or by creating a virtual network.

Game logic: Each player’s device runs a copy of the game software, and this software manages the game’s rules, physics, and interactions. Unlike traditional client-server models where a central server handles these tasks, in P2P gaming, each player’s device shares the responsibility.

Data synchronization: To ensure all players see the same game world and events, data is exchanged directly between players. This data includes information about player positions, actions, and game state. Players constantly send and receive updates to stay synchronized.

Benefits:

  • Lower latency: P2P gaming can offer lower latency compared to games that rely on centralized servers because data doesn’t have to travel to a central server and back.
  • Decentralization: There’s no need for a dedicated game server, reducing infrastructure costs for game developers.
  • Suitable for small groups: P2P gaming is often used for small groups of players, like friends playing together in the same room or over a local network.

Challenges:

  • Desync: It’s challenging to ensure that the game unfolds identically on every machine. Tiny differences, like a unit taking a slightly different path on two computers, can snowball into major discrepancies over time, causing the game to fall out of sync.
  • Slow players: The game has to wait until all players’ commands for a turn are received before simulating that turn. This means everyone in the game experiences delays equal to the slowest player’s internet connection. 
  • Lobbies: Because the game synchronizes by sending only the command messages that change the game state, all players must start from the same initial state. This usually means gathering in a lobby before beginning the game. While technically possible to support late join, it’s uncommon because capturing and transmitting a consistent starting point mid-game is complex.
  • Cheating: P2P gaming can be susceptible to cheating, as players have more control over the game’s inner workings on their devices.
  • Scalability: P2P gaming is typically not suitable for large-scale multiplayer games with many players because the complexity of synchronizing data increases with the number of participants.

P2P gaming is commonly used for games with small player counts, like cooperative or competitive games played among friends, especially in a local or LAN setting. However, for massively multiplayer online games (MMOs) or games with a large player base, a client-server model is more common due to its scalability and anti-cheating measures.

Client-server

While P2P gaming is primarily associated with local multiplayer (players connecting directly to each other’s devices in the same physical location), it’s not typically used in the context of online multiplayer where players are distributed across different locations and need to connect over the internet. In the online multiplayer scenario, a central server is generally used to facilitate communication, synchronize game state, and provide a more stable and fair gaming experience. The server is set up by the game developer, a third-party provider, or one of the players.

With the client/server model, players’ roles transformed. Instead of every player running the same game code and communicating directly with each other, each player became a “client” communicating with a single central “server.” The need for complete determinism across all machines vanished because the game’s true existence resided on the server. Each client now acted as a simple interface displaying an approximation of the game as dictated by the server.

In this model, clients don’t execute game code locally. Instead, they send inputs like keystrokes, mouse movements, and clicks to the server. The server processes these inputs (30 times per second for real-time games), updates the state of each player’s character in the game world, and sends back information about the game’s current state to the clients. All the client has to do is smoothly interpolate between these updates to create the illusion of seamless gameplay, and voilà, you have a networked game.

The quality of the gaming experience now depended on the connection between the client and the server, rather than being hindered by the slowest player’s lag. It also allowed players to join and leave the game at any time, and it improved scalability as client/server reduced the average bandwidth required per player. Many RTS games work in such a way (like Starcraft, but with slight modifications).

The client-server latency challenge

However, there were still challenges to address with the client-server approach. In the early days of online first-person shooter (FPS) games, you could feel the lag between your actions and their effects in the game. If you pressed the forward key, you had to wait for your command to travel to the game server and back before your character would start moving. The same applied to firing your weapon; you pressed the trigger and waited for the game to catch up.

The problem boiled down to latency—the time it takes for data to travel between the player’s computer, the ISP, and the game server, and back again. 

Causes of latency:

  • Network distance: The physical distance between a player’s device and the game server can affect latency. Longer distances generally result in higher latency because data packets take more time to travel back and forth.
  • Network congestion: If there is heavy traffic on the internet or within the network infrastructure, data packets may be delayed as they wait for their turn to be transmitted.
  • Server load: The workload on the game server can impact latency. A heavily loaded server may take longer to process and respond to incoming data from players.
  • Packet loss: Sometimes, data packets can be lost or dropped during transmission, leading to delays as they need to be resent.

Effects of latency:

  • Input delay: High latency can cause a delay between when a player performs an action (like pressing a button to shoot) and when that action is reflected in the game. This can make gameplay feel unresponsive.
  • Character jitter: Players’ characters or game objects may appear to jump around the screen or move erratically due to delayed updates from the server.
  • Unpredictable interactions: In fast-paced games, high latency can lead to unpredictable and unfair interactions between players, making it challenging to maintain a level playing field.
  • Hit registration issues: In games involving combat or shooting, latency can affect hit registration, causing shots that should hit to miss or vice versa.

Our experience

Teleport Battle VR-iX

A few years ago we worked on a project called Teleport Battle VR-iX, employing the client-server multiplayer approach. This game was tailored for HTC Vive, utilizing the Unity 3D game engine, with real-time multiplayer support facilitated by the Photon network. The game’s rules were elegantly simple and undeniably enjoyable:

  • Players stand on the pillars high in the sky.
  • One of the VR controllers lets you teleport to other pillars.
  • The second controller is a weapon that destroys pillars under your opponent/s.
  • Players had to make their opponent fall and avoid falling themselves.

A client-server approach worked well for this game. The direct control over character movements, encompassing head and arm motions in VR, remained isolated and did not impact the overall gameplay, nor was it visible to other players. Consequently, the data transmitted to the server and fellow players focused solely on teleportation and pillar destruction. Thus, the slight latency delay was entirely acceptable within this context.

Speed Crew

However, the scenario changes dramatically when dealing with fast-paced action games or those demanding simultaneous, interactive actions from multiple players. In such instances, even minimal latency can severely compromise the gaming experience, potentially rendering it unplayable.

Our most recent project, Speed Crew, developed in cooperation with Wild Fields, demanded speed and cooperation as its core elements. This chaotic party game revolves around team collaboration and precise time management while swiftly executing a range of pit-stop tasks, navigating intricate levels, and contending with environmental hazards.

For a project of this nature, we required a modernized solution for online multiplayer that would deliver speed, responsiveness, and precise synchronization among players. And here come input predictions and lag compensation techniques. 

Predictions

A concept known as “client-side prediction” implies that the client can make educated guesses about your character’s actions until it receives an authoritative response from the server. This was a significant shift from the previous model where the client merely sent inputs to the server and interpolated between states sent back.

Now, instead of being a passive transmitter, the client becomes proactive. It predicts your character’s movements locally and immediately responds to your input. Essentially, a portion of the game’s code for your character runs on your client’s machine. So, when you hit forward, there’s no waiting for data to travel back and forth between client and server – your character starts moving forward right away.

Similarly, the client attempts to predict the actions of other players based on the information it has locally, from the last interaction with the server. For example, if the other player is moving in a certain direction, the client predicts that they will continue in that direction until it receives updated information from the server. This prediction allows the player’s actions to be reflected immediately on their own screen, reducing the feeling of lag.

Prediction helps make the game feel more responsive for the player, even in the presence of latency. However, it can sometimes lead to visual discrepancies between what the player sees on their screen and what actually happens on the server. To address this, lag compensation is used to ensure fairness in player interactions when actions from different players need to be synchronized.

Lag compensation

Lag compensation is a technique used in online multiplayer games to mitigate the effects of network latency, or “lag,” on the gameplay experience. It aims to create a more fair and responsive gaming environment for players, especially in situations where players with varying levels of latency are interacting in the same game. Here’s how lag compensation works:

Latency in online gaming:

  • In online games, players are connected to a game server over the internet, and data packets travel between the player’s device (client) and the server.
  • Network latency causes delays in the transmission of data between clients and the server. This delay can result in situations where what a player sees on their screen is slightly behind the actual game state on the server.

Player interactions:

  • In multiplayer games, players often interact with each other, such as shooting at opponents or performing actions that affect the game world.
  • Without lag compensation, players with lower latency (lower ping times) would have a significant advantage because their actions would be registered on the server more quickly, making it harder for players with higher latency to react.

Lag compensation mechanism:

Lag compensation aims to level the playing field by taking into account the latency of each player. It works as follows:

  • When a player performs an action (e.g., shooting), the game server records the timestamp of that action.
  • When another player is affected by that action (e.g., getting shot), the server calculates the time it took for the data to travel from the shooter to the target player.
  • The server then sends data to the target player client, and it “rewinds” the game state to the point in time when the shooter’s action occurred, essentially compensating for the shooter’s latency.
  • The game simulates the impact of the action as if it had happened at that earlier moment.
  • This ensures that even players with higher latency see actions from other players in a way that feels fair and synchronized with the game world.

Lag compensation primarily focuses on ensuring fair and synchronized interactions between players with varying latencies, while prediction aims to provide a smoother and more responsive gameplay experience for individual players by reducing the perceived effects of latency. Both techniques are often used in combination to create a balanced and enjoyable online multiplayer gaming experience.

Although explained in a simplified manner, this is how modern FPS games work and manage to eliminate this server-client communication delay in multiplayer action. This synergy of lag compensation and prediction was instrumental in enabling us to develop a high-speed multiplayer mode for our partner’s game, Speed Crew.

What to consider when creating a multiplayer game

Think about multiplayer from the get-go

When creating a multiplayer game, making fundamental architectural decisions from the project’s outset is paramount. The choice between peer-to-peer or client-server models, network protocols, and scalability plans profoundly impacts the game’s performance and player experience. Ignoring these choices early on can lead to complex and costly rewrites later in development.

Multiplayer functionality is a continuous effort

Multiplayer isn’t a feature that’s bolted onto a game at the end or something that can be done once at the beginning and forgotten late. It’s a continuous commitment throughout the entire production pipeline. Regular testing, debugging, and updates are essential to maintain a stable and enjoyable multiplayer experience. Neglecting this ongoing effort can result in frustrated players and diminishing community interest.

Estimate time and budget

Implementing multiplayer functionality can be demanding, often requiring 1.5 times more work and time than developing a single-player game. This includes networking code, synchronization, anti-cheat measures, and server infrastructure. Developers should budget for this extra workload and plan accordingly to ensure a successful multiplayer game launch. Cutting corners here can lead to technical issues and player dissatisfaction down the road.

Create your multiplayer game with N-iX Game & VR Studio

Ready to bring your multiplayer game vision to life? N-iX Game & VR Studio’s experts in game development and virtual reality are poised to turn your ideas into captivating multiplayer experiences. From cutting-edge technology to seamless networking solutions, we have the tools and expertise to make your game a reality. Drop us a line and let’s craft the next big thing in multiplayer gaming together.

getintouch

Get in touch

Let’s start with an in-depth analysis of your idea and a high-level quote and project plan for your project. Once we smoothen all the rough edges we can proceed to the complete design, development, and production of your game, followed by release and post-release support.

Static Image

    By submitting the request, you consent to processing of your personal data, acquainted with personal data processing and privacy policy.