Posted on

Photon Transform View with Photon 2 in Unity

Here is the next lesson on how to make a multiplayer game in Unity using the Photon 2 plugin. For this lesson, we will be focusing on player movement and synchronizing the transform across the network using the photon transform view. It is very important to be able to sync player movement across the network because without doing so players will be able to see each other in different locations then they actually are. It is also important to make sure that each player can only control his own avatars.

The first thing that we need to do is open up our Photon Player Avatar prefab. On this prefab, we will add the Photon Transform View so that our player avatar can have its movement synchronized. We will then need to create a new C# script for setting up the controls for the movement of the Avatar object. With this C# script opened the first thing we will do is create some new variables. We will then initialize all our variables. As we create the movement functions we first need to check for the player’s input. Based on the player’s input we will then move the player avatar object. When we call these movement functions is the update function we will use the Photon View variable to check to see if this object is owned by the local player. This is to make sure that only the local player can control their avatar and not other people’s avatars. We will then save our script and return to Unity 3D.

If you follow along with the video you should now be able to build your project. In the multiplayer scene, you should be able to now control the movement of only your local player avatar.