Creating Your First Multiplayer Game in Godot
This comprehensive guide shows you how to create a simple multiplayer game from scratch in Godot that connects to a dedicated server hosted on PlayFlow Cloud. This setup is compatible with both web and desktop platforms using TCP + TLS (“wss” protocol).Complete Project
What You’ll Build
By the end of this tutorial, you’ll have:- A 3D multiplayer game with player movement
- Connection UI for server details
- WebSocket networking with TLS support
- Multiplayer synchronization using Godot’s built-in systems
- A working dedicated server setup on PlayFlow
Before We Begin
Create New Project
Set Up Main Scene
Part 1: Building the Connection UI
Let’s start by creating the user interface that players will use to connect to your PlayFlow server.Create Connection Display
- Open
main.tscn
and add a child node of type Control - Rename it to “ConnectionDisplay”
- Set Custom Minimum Size to X: 256.0px and Y: 128.0px
Add Container Layout
- Add a child node to “ConnectionDisplay” of type VBoxContainer
- Set Layout Mode to Anchors and Anchors Preset to Full Rect
Create URL Input Field
- Add a child node to “VBoxContainer” of type HBoxContainer
- Add a TextEdit child to “HBoxContainer” and rename it to “UrlInput”
- Set Placeholder Text to “Url”
- Toggle on Fit Content Height
- Set Custom Minimum Size to X: 192.0px and Y: 32.0px
- Toggle on Expand under Horizontal
Create Port Input Field
- Add another TextEdit child to “HBoxContainer” and rename it to “PortInput”
- Set Placeholder Text to “Port”
- Toggle on Fit Content Height
- Toggle on Expand under Horizontal
Add Connection Buttons
- Add a Button child to “VBoxContainer” and rename it to “ConnectButton”
- Set Text to “Connect”
- Add another Button child to “VBoxContainer” and rename it to “DisconnectButton”
- Set Text to “Disconnect”
Set Unique Names
Create Connection Display Script
- Right-click “ConnectionDisplay” and select Attach Script
- Create a new script called “connection_display.gd”
- Add the following code:
Connect Button Signals
- Select the “ConnectButton” and go to the Node tab next to the Inspector
- Connect the “pressed()” signal to “ConnectionDisplay”
- Repeat for “DisconnectButton”
Add Game Environment
- Add a child node to “Main” of type MeshInstance3D and rename it to “Ground”
- Assign a new PlaneMesh to the Ground
- Set the PlaneMesh Size to X: 10m and Y: 10m
- Add a child node to “Main” of type Node3D and rename it to “Players”
- Add a child node to “Main” of type MultiplayerSpawner
- Add a Camera3D as a child to “Main” and position it as desired
- Add a DirectionalLight3D as a child to “Main” and rotate it (suggested: X: -60.0)
Part 2: Creating the Multiplayer Manager
Now we’ll create a Multiplayer Manager to handle all networking aspects of our game.Create Multiplayer Manager Scene
- Create a new scene, save it as “multiplayer_manager.tscn”
- Select Node as the root type
Create Multiplayer Manager Script
- Right-click the root node and select Attach Script
- Create a new script called “multiplayer_manager.gd”
- Add the following code:
Add as Autoload Singleton
- Go to Project → Project Settings → Autoload
- Set Path to “res://multiplayer_manager.tscn”
- Set Node Name to “MultiplayerManager”
- Click Add
Part 3: Creating the Player
Let’s create the player character with movement and networking synchronization.Create Player Scene
- Create a new scene, save it as “player.tscn”
- Select 3D Scene as the root type (this creates a Node3D)
- Add MeshInstance3D as a child to Player
- Assign a CapsuleMesh to the MeshInstance3D
- Move the MeshInstance3D up by Y: 1.0m so it sits on the ground
Add Network Synchronization
- Add a MultiplayerSynchronizer as a child to Player
- In the MultiplayerSynchronizer, click Add property to sync
- Select Player → position under Node3D
Add Player to Group
- Select the Player root node
- Go to the Groups tab next to the Inspector
- Add the player to group “Players” (type “Players” and click Add)
Create Player Script
- Right-click the Player root node and select Attach Script
- Create a new script called “player.gd”
- Add the following movement code:
Part 4: Input Mapping and Player Spawning
Configure Input Map
- Go to Project → Project Settings → Input Map
- Add these input actions (click Add New Action for each):
move_forward
- Assign W key and Up Arrowmove_backward
- Assign S key and Down Arrowmove_left
- Assign A key and Left Arrowmove_right
- Assign D key and Right Arrow
Create Player Spawning System
- In
main.tscn
, select the MultiplayerSpawner node - Right-click and Attach Script, create “spawner.gd”
- Add the following code:
Configure MultiplayerSpawner
- Set Spawn Path to “Players” (the Node3D we created earlier)
- Under Auto Spawn List, click Add Element
- Set the scene path to “res://player.tscn”
Part 5: Server Export Configuration
Add Linux Export Preset
- Go to Project → Export
- Click Add… and select Linux/X11
- Rename the preset to “Linux Server”
- IMPORTANT: Set the export path filename to “Server” (required by PlayFlow)
Configure for Dedicated Server
- In the Linux Server preset, go to the Resources tab
- Set Export Mode to “Export as dedicated server”
- This will create a headless server build suitable for PlayFlow
Export the Server
- Click Export Project…
- Choose your export location
- Toggle Export With Debug for development builds
- Click Save
Create Archive
Part 6: Deploy to PlayFlow and Test
Upload to PlayFlow
- Create your PlayFlow account at app.playflowcloud.com
- Create a new project for your Godot game
- Upload your server .zip file to PlayFlow
Configure Network Port
- Set Port Number to 8080 (matches our server code)
- Set Protocol to TCP
- Enable TLS - This is required for “wss://” protocol used in browser games
Start Server Instance
- Create and start a server instance in PlayFlow
- Copy the Host URL and External Port from the server details
Test the Connection
- Run your Godot project locally (you can enable Multiple Instances in Debug settings for testing)
- Enter the PlayFlow Host URL in the “Url” field
- Enter the External Port in the “Port” field
- Click Connect
- Your player should appear and you can move around with WASD keys!
Technical Architecture
Network Setup
- Protocol: WebSocket with TLS (“wss://”)
- Server Port: 8080 (internal)
- Synchronization: Player position only
- Authority: Server-authoritative with client input
Key Components
- MultiplayerManager: Handles connection logic and server detection
- Player: Networked player with movement and authority management
- ConnectionDisplay: UI for entering server connection details
- MultiplayerSpawner: Automatically spawns players when clients connect
Platform Support
- Desktop: Windows, Linux, macOS
- Web: Browser support via WebSocket + TLS
- Server: Headless Linux builds for PlayFlow
Next Steps
Advanced Networking
Lobby System
WebGL Deployment
Common Issues
Connection timeout or 'wss://' connection failed
Connection timeout or 'wss://' connection failed
- Verify the server URL and port are correct
- Ensure TLS is enabled in PlayFlow port configuration
- Check that the PlayFlow server instance is running
- For local testing, use “ws://” instead of “wss://” (localhost only)
Players not synchronizing or appearing
Players not synchronizing or appearing
- Check that MultiplayerSynchronizer is properly configured on the player
- Verify the player scene is added to MultiplayerSpawner’s Auto Spawn List
- Ensure players are being added to the “Players” group
- Check that spawn_function is set correctly in spawner.gd
Server not starting automatically
Server not starting automatically
- Verify MultiplayerManager is added as an Autoload singleton
- Check that
OS.has_feature("dedicated_server")
returns true in server builds - Ensure the “Export as dedicated server” option is enabled in export settings
Input not working
Input not working
- Check that input actions are properly defined in Project Settings → Input Map
- Verify
is_multiplayer_authority()
check in player movement code - Ensure the player has authority set via
set_multiplayer_authority()
Resources
- Godot Documentation: docs.godotengine.org
- Godot Multiplayer: docs.godotengine.org/en/stable/tutorials/networking
- PlayFlow Documentation: documentation.playflowcloud.com
- Complete Project: GitHub Repository