Hi everyone,
Since multiplayer can often be a complex topic to approach and implement, with various different frameworks available and not too many public projects/starter kits to study and/or fork, I thought it would be a good idea to develop a small and very basic multiplayer starter project which PlayCanvas users can use as a basis for all kinds of multiplayer projects. Please do go through the short guide below before forking the project if you do not have prior experience with Photon/multiplayer frameworks.
The Framework
The starter kit uses the fantastic Photon for PlayCanvas plugin developed by @Ryotaro.TSUDA. All the files required are already included in the project. Photon makes developing real-time multiplayer very easy while also keeping quality and speed high, leading to a smooth experience for players. For ease of development, the starter kit uses Photon real-time Cloud, though the project is fully capable of supporting Photon Server if required. On the free plan, up to 20 users are supported; the paid plans will increase this user limit.
The Project
The starter kit is a very basic project loosely based on the concept of the official PlayCanvas real-time multiplayer tutorial, where users can move around as capsules around a defined space. To integrate your own Photon Cloud into the application, you must first navigate to “Root” in the hierarchy, and add your app details accordingly. Here, only the AppID, app version(ensure it is always 1.0), and region spaces must be filled, and others left blank. Please note that the free version of Photon only supports up to 20 users, and any more will require a paid subscription to their services. The “Manager” entity contains the script manager.js
, which handles the creation of multiplayer entities in the game/app. Please study this script carefully as it will serve as the basis for a multiplayer project using Photon. To understand how to transmit data from one player to the others, such as position, please study the file transmit.js
, and to understand how to receive this transmitted data, please study the file receive.js
. Further examples can be found in the official docs for the Photon for PlayCanvas plugin.
Conclusion
I really hope that this guide helps those of you who want to create multiplayer games and/or apps in PlayCanvas. Please find the starter kit project here. Good luck!