Photon lags

Hello i need Help… My player lags if moving
my script works but not good

here is video:

and here is script :

using UnityEngine;

public class PhotonTransform : Photon.MonoBehaviour, IPunObservable
{

    Vector3 _networkPosition;
    Quaternion _networkRotation;
    Rigidbody _rb;

    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.isWriting)
        {
            stream.SendNext(_rb.position);
            stream.SendNext(_rb.rotation);
            stream.SendNext(_rb.velocity);
        }
        else
        {
            _networkPosition = (Vector3)stream.ReceiveNext();
            _networkRotation = (Quaternion)stream.ReceiveNext();
            _rb.velocity = (Vector3)stream.ReceiveNext();

            float lag = Mathf.Abs((float)(PhotonNetwork.time - info.timestamp));
            _rb.position += _rb.velocity * lag;
        }
    }

    void Start()
    {
        _rb = GetComponent<Rigidbody>();
    }

    public void FixedUpdate()
    {
        if (!photonView.isMine)
        {
            _rb.position = Vector3.MoveTowards(_rb.position, _networkPosition, Time.fixedDeltaTime);
            _rb.rotation = Quaternion.RotateTowards(_rb.rotation, _networkRotation, Time.fixedDeltaTime * 100.0f);
            return;
        }
    }
}

Did you try the PhotonTransformView or PhotonTransformViewClassic components?

yes he does it too

You mean the problem is the stuttering movement, right?

The PhotonView Synchronization is set to Unreliable On Change?
It seems like your interpolation between updates is “missing”. This should be a bit better in the original components.

i buy https://assetstore.unity.com/packages/tools/network/smooth-sync-96925 and lagy are gone … thanks

1 Like