Beginning to explore a completely different approach to synchronizing.
This article is part of the series starting with Synchronization Issues (Unity + Photon): Part 1.
Sidebar into a Photon Provided Solution
In researching the specifics of the theoretical solution to problems arising from network lag (from last article), I bumped into an article written by Photon on the topic; Lag Compensation.
The solution amounted to writing a custom Observed Component that behaves much like the Photon Transform View (position synchronization) and Photon Rigidbody View (velocity synchronization) used together; but with an extra compensation for network lag.
The resulting behavior was:
- First, the movement of the balls in the two applications is indeed more synchronized
- The right application (did not instantiate the ball) does show some anomalies, e.g., double-bounces, here and there. These anomalies are more frequent and more severe as the lag is increased.
- Because the we are still fundamentally having the left application (instantiated the ball) control the position of the ball, we still have the problems from the previous article (red wall problem that illustrates the Pong problem)
Synchronizing Initial Movement
Here we are going to take a dramatically different approach by first getting rid of the networked ball from our earlier example:
- Remove the line instantiating the ball in OnPhotonPlayerConnected in GameManager.cs
- Remove the Ball prefab
- Remove Ball.cs
- Remove the code in moving the ball in HandleClick in Serve.cs
Now, we go back and recreate the ball (Ball) in the scene; just a plain-old game object with a Rigidbody component.
The next steps enables the Serve button to do two things:
- Start the movement of the ball in the local application
- Make a remote procedure call (RPC) to the remote application to position and start the movement of the ball (accounting for network lag)
First, we add a Photon View component to the Serve game object. We then update Serve.cs.
With this in place we see that that the two balls are synchronized with no unusual artifacts like we saw in the previous example.
If, however, if we left this running for a long time we would expect the positions of the ball to slightly drift as the balls’ positions are never re-synchronized.
In the next article, Synchronization Issues (Unity + Photon): Part 4 we will work in synchronizing collisions (with the paddles).