In the second part of our pong series, you’ll be creating a fully synchronized multiplayer game using Elympics. Let’s dive in!
Awesome! Let’s take a look at what you’ve just added to your Unity 2D pong.
Let’s leave these settings at default for now. As we need to add position synchronization, let’s focus on the three buttons at the bottom: Add Game Object Active Synchronization, Add Transform Synchronization and Add Rigidbody 2D Synchronization.
You’ve just added Elympics Rigidbody 2D Synchronizer to the ball object. It allows you to tweak synchronization settings and parameters such as the required precision. For now, let’s leave these at default.
That’s it! The ball movement is fully synchronized between the players of your Unity 2D pong. Every player connected to the game will be able to see the current ball position and velocity, in the same way as on the server instance.
Half remote mode
To test what you’ve just created, you’ll need to use the half remote mode. It’ll allow you to host both server and client games between multiple editor instances and/or game builds.
In this case, one of the editors will act as a server, and all others will join as players (clients). Here comes a very convenient package bundled with Elympics: ParrelSync.
Once it’s done, you should see two clones of launchable Unity instances.
To test our ball synchronization, you’ll need only one additional clone (for player 1). Click Open in New Editor in Clone 0 to launch another Unity editor with the same exact project that will be the player during our tests.
Now, set the main editor as Server in the half remote mode.
In the second editor (Player 0), edit the same settings and set it as Player. Connect the localhost IP to your loopback (the same as in the screenshot below).
Player 1 should be set to bot so that you can start the game with one player only. Alternatively, you can create another editor clone and launch it as the second player.
That’s it! You should be able to test your game. 🎉
First, start Play mode in the editor that was configured as the server. Once it starts, do the same in the clone editor (player). At first, nothing exciting will happen, but when you try “playing” in the server editor, you’ll see that the ball is bouncing in the client editor as well despite not hitting the pad. It means that the ball is now fully synchronized and streamed to the client from the server.
Inputs: moving player pads
When creating a multiplayer game, you don’t need to distinguish which player is responsible for a certain input. Elympics will handle and abstract it for you. You can change the implementation to:
That’s it! 🎉 But we’re not finished yet.
Applying input: reading and applying players’ inputs to the game world using ElympicsUpdate
Player pad synchronization
Don’t forget to test what you’ve done! You’ll need one editor for the server and two clones for both players (remember to uncheck Is Bot for player 1).
You’ve just created a fully synchronized multiplayer Unity 2D pong game using Elympics! 🎉🎉
In the next Unity 2D tutorial from this series, we’ll use synchronized variables to save our match score in a deterministic and safe way. Stay tuned!
In the meantime, remember to visit our Discord where you'll find Elympics project updates and tech support from our developers.