Warm tip: This article is reproduced from serverfault.com, please click

Synchronising drawing using PUN

发布于 2019-06-12 10:45:56

I have implemented annotation feature which is similar to drawing in VR. Drawing is a Unity trail and its shape depends on its trajectory. This is where real problem comes. We are synchronising the drawing in realtime using PhotonTransformView which syncs world position of the trail. But here is the output. The synchronised drawing looks so different from the original one.

Here is sync configuration code:

public void SetupSync(int viewId, int controllingPlayer)
{
   if (PhotonNetwork.inRoom)
   {
      photonView = gameObject.AddComponent<PhotonView>();
      photonView.ownershipTransfer = OwnershipOption.Takeover;
      photonView.synchronization = ViewSynchronization.ReliableDeltaCompressed;
      photonView.viewID = viewId;

      photonTransformView = gameObject.AddComponent<PhotonTransformView>();
      photonTransformView.m_PositionModel.SynchronizeEnabled = true;

      photonView.ObservedComponents = new List<Component>();
      photonView.ObservedComponents.Add(photonTransformView);
      photonView.TransferOwnership(controllingPlayer);
   }
}

How can we make the drawing on two systems more similar? I have seen cases where people have been able to synchronise these perfectly. Check this. What are they doing?

Questioner
Harsh Priyadarshi
Viewed
0
2020-08-07 05:03:30

Yes, PhotonTransformView is not suitable for this.

You could send a reliable rpc every x milliseconds with the list of points since the last rpc. That's when it's being drawn live, and when the drawing is finished, you cache the whole drawing definition in a database given a drawing Id. Then drawings can be retrieved later by players joining the room after the drawing was done or even loaded from a list of drawing or by any arbitrary logic.

All in all you need two different system, one when drawing is live, and one when drawing is done.