Synchronization Issues (Unity + Photon): Part 2

We make our first stab at synchronizing the ball using Photon components.

Image for post
Image for post

This article is part of the series starting with Synchronization Issues (Unity + Photon): Part 1.

Photon Transform View

The Photon tutorial uses a Photon Transform View to synchronize the position of the players

This class helps you to synchronize position, rotation and scale of a GameObject. It also gives you many different options to make the synchronized values appear smooth, even when the data is only send a couple of times per second. Simply add the component to your GameObject and make sure that the PhotonTransformView is added to the list of observed components

— Photon — PhotonTransformView Class Reference

Let us start by using this approach. Simply add a Photon Transform View to the Ball prefab and assign it as an Observed Component on the Ball’s Photon View component.

Image for post
Image for post

With this in place, the behavior looks fairly synchronized.

Image for post
Image for post

Observations:

Photon Rigidbody View

This class helps you to synchronize the velocities of a physics RigidBody. Note that only the velocities are synchronized and because Unitys physics engine is not deterministic (ie. the results aren’t always the same on all computers) — the actual positions of the objects may go out of sync. If you want to have the position of this object the same on all clients, you should also add a PhotonTransformView to synchronize the position.

— Photon — PhotonRigidbodyView Class Reference

From the documentation, it seemed like the correct practice (in this case) to also add a Photon Rigidbody View component and add it as an Observed Component.

note: This had no visible impact on how the synchronization appeared in this example.

Image for post
Image for post

Network Lag

Let us consider how network lag, aka, ping or RTT (round-trip-time), can affect the synchronization of the position of our ball.

Many people assume that a fast, responsive internet connection relies solely on a good download and upload speed, but there’s more to it than that. There’s also ping, which is essentially a reaction time. If you have a ping of 98ms (milliseconds) that’s the time it has taken for your computer to respond to a request by another computer.

Anything below a ping of 20ms is considered to be great, while anything over 150ms could result in noticeable lag.

— Tech Advisor — How to lower your ping

We can use the Photon Lag Simulation Gui component, say adding it to the GameManager game object to test the application under varying network conditions.

Image for post
Image for post

Looks like my home’s 151ms RTT is just marginal.

Thinking about how Photon works, each application is communicating with the Photon servers, it actually takes the sum of both player’s RTT for information to go between applications; e.g., 300ms. So, looking back at our first attempt at synchronizing the balls’ movement we can now better understand the delay.

In both instances of the application, I enable the simulated lag (both applications’ RTT is around 340ms). With the combined delay being around 700ms, we are close to a full second between information being communicated between applications.

Image for post
Image for post

Observations:

Next Steps

In the next article, Synchronization Issues (Unity + Photon): Part 3, we explore some more fundamental problems that network lag can pose.

Written by

Broad infrastructure, development, and soft-skill background

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store