- Home /
Syncing movement and rotation lag in multiplayer scene
Hello everyone,
I have a room that uses PUN 2, where two agents connect and wander around the scene. I am using the first person controller from Unity standard assets without a rigid body but a character controller. However, the problem is that when the agents connect in a complete room with assets and lighting the movement of the other client (the one we watch as players) has quite some lag. When I tried in a room with just a cube as ground everything works fine and no lag at all.
I have implemented lag compensation based on the documentation using the transform component. Here is the following code :
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.IsWriting)
{
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
}
else
{
networkPosition = (Vector3)stream.ReceiveNext();
networkRotation = (Quaternion)stream.ReceiveNext();
}
}
and the update function
if (!photonView.IsMine)
{
transform.position = Vector3.Lerp(transform.position, networkPosition, Time.deltaTime * 5);
transform.rotation = Quaternion.Lerp(transform.rotation, networkRotation, Time.deltaTime * 5);
}
All this belongs to the script that is inserted as input to the PhotonView component. What can you suggest for solving this problem with the sync lag ?
Thanks in advance.
Hey there,
can't see any obvious mistakes here, so i'd suggest you do 2 things: First try to use the transform view the comes with photon. (So ofc disable all strea$$anonymous$$g and reciever side position update code that you wrote yourself) If the problem still persists add your environment part by part and see where it starts lagging. You should be able to just disable all objects and the you can put them in at runtime again.
Also a look at the Performance Profiler might be helpful.