Lag Compensation (PUN)

Options
So I'm working on a game by "Scorpion_Trail Studios" that is competitive and needs intense position synchronization. This is the lag compensation script that has produced the most current results (still not great), but its very snappy:
public class CustomPhotonTransform : MonoBehaviour, IPunObservable
{
             // Values that will be synced over network
        Vector3 latestPos;
        Quaternion latestRot;
             //Lag compensation
        float currentTime = 0;
        double currentPacketTime = 0;
        double lastPacketTime = 0;
        Vector3 positionAtLastPacket = Vector3.zero;
        Quaternion rotationAtLastPacket = Quaternion.identity;

        public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
        {
             if (stream.IsWriting)
             {
                      // We own this player: send the others our data
                 stream.SendNext(transform.position);
                 stream.SendNext(transform.rotation);
             }
             else
             {
                      //Network player, receive data
                 latestPos = (Vector3)stream.ReceiveNext();
                 latestRot = (Quaternion)stream.ReceiveNext();

                      //Lag compensation
                 currentTime = 0.0f;
                 lastPacketTime = currentPacketTime;
                 currentPacketTime = info.SentServerTime;
                 positionAtLastPacket = transform.position;
                 rotationAtLastPacket = transform.rotation;
             }
         }

        // Update is called once per frame
         void Update()
         {
             if (!pv.IsMine)
             {
                    //Lag compensation
                 double timeToReachGoal = currentPacketTime - lastPacketTime;
                 currentTime += Time.deltaTime;

                      //Update remote player
                 transform.position = Vector3.Lerp(positionAtLastPacket, latestPos, (float)(currentTime / timeToReachGoal));
                 transform.rotation = Quaternion.Lerp(rotationAtLastPacket, latestRot, (float)(currentTime / timeToReachGoal));
             }
         }
}   

We need to figure out how to get position synchronization like Rainbow6Siege, Pubg, Apex legends, COD, Fortnite. Any help is extremely appreciated!

Comments

  • jc_kolbapps
    edited March 2021
    Options
    Hello, I am also having a lot of problems with this. The standard synchronization component of PUN2, due to transformations or physics, is very precarious. The documentation mentions 2 ways to create compensation, and I implemented it in my current prototype, but it is still very weak.
    I paid for some tutorials and also saw others for free, and none solved the problem. I even implemented the solution you mentioned above. Nothing works elegantly.

    My current prototype, can be checked at this link: https://simmer.io/@jcpereira/megaman-prototype

    For him I am using the example described in the documentation.

    For the projectiles I used the same system as the Asteroid game, existing in the example package of PUN2. I made a small improvement to not teleport the projectile, but nothing too sophisticated.

    Anyway. playing the prototype, the bad movement caused by the lag is noticeable. Even in pings below 80, it never looks good !.

    Could someone with experience share knowledge with us, please? What is the path to light here?
  • Tobias
    Options
    Reid wrote: »
    We need to figure out how to get position synchronization like Rainbow6Siege, Pubg, Apex legends, COD, Fortnite. Any help is extremely appreciated!

    Sorry for the late reaction.
    To keep this short: PUN 2 is not in the same class of networking solutions as your references.

    Our upcoming networking solution Fusion will do everything possible to get you there with up to date foundations for network synchronization.

    Maybe have a look at our addon "Simple" for PUN 2 and or have a look at Smooth Sync.
  • sdsdink
    Options

    When can we expect to see fusion?

  • Tobias
    Options
    In a few weeks.