Lesson 1-1: Network Architecture and Input System
Introduction to Multiplayer
Welcome to Unity 3! In this course, we will be looking at how to implement multiplayer games. From previous courses, you have learned how to create games in Unity, focusing on single-player experiences. Now, we are going to look at networking concepts and multiplayer game design to create multiplayer games.
Networking Introduction
Some Important Concepts
- Netcode: Code related to the networking side of games.
- Client: For multiplayer games, this is a computer that interacts with the user, sends local information to the server, and then displays results from the server. Each player in a multiplayer game represents one client.
- Server: In multiplayer games, this is the computer that processes information sent by clients and then synchronizes changes between all the connected client. The server is most often the full authority of the game state.
- Host: A special kind of client that also has acts as a server, which allows other clients to connect to it. This allows other players to connect together without needing a separate dedicated server.
- Network: A collection of clients and servers that are connected together in some way.
Unity provides more networking and multiplayer concepts here:
Network Architecture
There are many ways to connect multiplayer clients together. Here are 3 major types of network connections that are used in multiplayer and some information about them.
- Peer-to-Peer: Each client is connected to every other client and each client behaves as their own server.
- Minimum Connections Required = (C * (C - 1)) / 2 where C is # of clients
- Pros: Very easy to setup, fast response
- Cons: Does not scale well (imagine connecting 4 players compared to 64 players), hard to synchronization if not designed well
- Server-Client: There is a central server that is separate from every client. All clients (including the one that starts the game) will connect to the same server to play.
- Minimum Connections Required = C where C is # of clients
- Pros: Full control over client interaction, prevents cheating by host, simple to scale up (add more servers as the game grows)
- Cons: Expensive to setup (you need to pay for a separate server), single point of failure
- Host-Client: One player hosts the game, which will be the server for all other clients connect to.
- Minimum Connections Required = C - 1 where C is # of clients (host does not need to connect anywhere)
- Pros: Easy to setup, server manages syncing all changes
- Cons: Host has server advantage (almost no delay when a change is made, also can maliciously change unsecure servers easily), single point of failure (if the host goes down, the entire game ends; host migration can fix this issue)
You can find some illustrations and additional information from Unity's documentation on Network Topologies.
For this course, we will be focused mainly on Host-Client architecture as this is the most easiest to setup (compared to Server-Client) while also being easy to synchronize (compared to Peer-to-Peer).
Preview of Modules
Over this course, we will be taking the concepts we learn applying them to create many different kinds of games. Our main overarching project will be a version of Pong. Pong is a simple two player game where each player controls a paddle and tries to score by getting a ball into their opponent's goal. The simplicity of the game will allow you to focus on getting the system working without worrying too much about the mechanics. However, you will have the opportunity to customize the game in you own ways.
Here is a high-level overview of the modules:
- Module 1: Focus on creating a local multiplayer game. Users are on the same computer, but can control with different input devices.
- Module 2: Focuses on creating a LAN version of the game, which allows players on the same network to join.
- Module 3: Focuses on creating a fully Internet connected game, to allow players to join from any network.