8 months ago

This is long overdue. Many people have been asking how we network players in Convrge and I’ve been promising a tutorial for a while. We’ve gone through a few iterations of different techniques ourselves and I wanted to spill the beans in this post to help other aspiring virtual reality developers be able to network their own games. One of the driving forces of creating Convrge in the beginning was the mismatch between how cool multiplayer VR experiences are and how few were actually available. Hopefully this post will help even out that mismatch, and help you add multiplayer to your virtual realities.

The tools are surprisingly easy to use:

Unity Game Engine

Photon Cloud (by Exit Games)

Oculus Unity Integration

One thing to note here is that many, many multiplayer Oculus experiences already use these same tools. The “oh cool, what are you using for networking?” conversations usually end up pretty boring because the answer is almost universally “Photon.” Photon works very similarly to the standard built-in Unity networking tools which makes it very approachable, while also having a lot of advanced features and flexibility. Currently we use their PUN+ edition which allows up to 100 people on your app concurrently for a once off price of $99. Pretty groovy.

As I’m writing this I’ve realized how much easier this tutorial would be in video form, so I’m going to write out the general bullet points of the process and record the step-by-step in a video.

Here is the video (probably worth full screening it to see the text):

Here are the bullet points:

Import the Photon and Oculus Unity integrations.

Drag the Oculus Player Controller prefab into your scene.

Create a C# script to handle connecting to the network and instantiating the player, attach this to an empty GameObject (script is copied below).

Create a C# script to handle the player synchronization (script is copied below).

Create an empty GameObject for the player synchronization, add a photon view to this, and add the above script component to this.

Turn this GameObject into a prefab by dragging it into the Resources folder (this is also necessary to use this prefab with the Photon instantiate call).

Once the player prefab is instantiated we attach our own player to the CenterEyeAnchor of the Oculus Player Controller. Then we use the position/rotation of the Player controller for the global position of your avatar and the position/rotation of the CenterEyeAnchor for the local position.

Voila. Start game.