Problem to synchronize the position of game objects

Options
Hi! I'm new with PUN and because of that I am having some issues to synchronize players positions.

I have two game objects which move horizontally or vertically in a constant speed, depending on the player input. Each game instance is running in different PCs, and they use Photon Cloud to share their position, animation state, and direction. As you can see in the following figures, when we move these game objects to the left almost at the same time, the distance between them differ in each game. The fact is that they should be near, as the second figure shows (the flag and the map are generated randomly and their information are not being shared among players, so do not consider that).

sync_problem1.png
Player in the PC1 (wrong position)

sync_problem2.png
Player in the PC2 (right position)

This game object has a Photon View component to sync its status. The figure below shows the setup of the Photon View in this game object.

player_game_object.png

Besides, below we have the code of SyncPlayer class:
public class SyncPlayer : Photon.MonoBehaviour
{
	void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
	{
		if (stream.isWriting)
		{
			Player playerComponent = GetComponent<Player>();

			stream.SendNext(transform.position);
			stream.SendNext((float) playerComponent.hInput);
			stream.SendNext((float) playerComponent.vInput);
			stream.SendNext((int)playerComponent.Direction);
		}
		else
		{
			Player playerComponent = GetComponent<Player>();

			transform.position = (Vector3)stream.ReceiveNext();
			playerComponent.hInput = (float)stream.ReceiveNext();
			playerComponent.vInput = (float)stream.ReceiveNext();
			playerComponent.Direction = (int)stream.ReceiveNext();
		}
	}
}

Is there a better way to synchronize their positions in order to avoid this distance problem? I am from Brazil, so the delay might be relatively high to send data to Photon Cloud. Can delay be a cause for the problem?

Best regards!

Comments

  • vadim
    Options
    Hi,

    You may try different position sync techniques from DemoSynchronization demo.
    If movement as simple as direct moving between points, you can achieve almost perfect synchronization if calculate position basing on PhotonNetwork.time, velocity and position at last segment start point. Of course object jumping is possible in this case due to latency but you can smooth it with interpolation.