Custom Transform Sync NEED HELP on code implementation

Options
I am creating fast paced racing game. A car can speed up to 10m/s in unity unit, so syncing must to smooth as hell. And I wrote this class with lag compensation:
public class CustomPhotonView : MonoBehaviourPunCallbacks, IPunObservable {
    Vector3 networkPosition;
    Quaternion netWorkRotation;
    float speed;
    public float rotateSpeed = 180f;

    void Update() {
        if (!photonView.IsMine) {
            transform.position = Vector3.MoveTowards(
                transform.position,
                networkPosition,
                speed * Time.deltaTime
            );

            transform.rotation = Quaternion.RotateTowards(
                transform.rotation,
                netWorkRotation,
                Time.deltaTime * rotateSpeed
            );
        }
    }

    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) {
        if (stream.IsWriting) {
            stream.SendNext(car.sphereRigidBody.position);
            stream.SendNext(transform.rotation);
            stream.SendNext(car.sphereRigidBody.velocity);
        } else {
            if (info.SentServerTime > last) {
                networkPosition = (Vector3)stream.ReceiveNext();
                netWorkRotation = (Quaternion)stream.ReceiveNext();
                Vector3 velocity = (Vector3)stream.ReceiveNext();

                float lag = Mathf.Abs((float)(PhotonNetwork.Time - info.SentServerTime));
                networkPosition += velocity * lag;

                last = info.SentServerTime;

                speed = Mathf.Abs(Vector3.Distance(transform.position, networkPosition) * PhotonNetwork.SerializationRate);
            }
        }
    }
}


Unfortunately, syncing is not smooth, giving me jittering effect. And another problem is that my hometown's internet connection can get no more less than 140ms ping to the photon servers. I am so confused right now with these codes. I don't know whether this is happening because of my unstable fluctuated connection or whether my code is wrong. I don't know.

Plz help guys

@JohnTube

Comments

  • Tobias
    Options
    You could tell us how the PhotonTransformView or the PhotonTransformViewClassic compare to your own, custom synchronization. If those are any better, you got a nice blueprint...
  • 127STUDIOGAMES
    edited January 2021
    Options
    @Tobias
    My friend in USA just tested the game. And it was smooth. I saw it on a video. It was my country's internet problem. But lag compensation didn't work. And I multiplied the equation by 1.71f and lag compensation works. But I don't know why 1.71f? Do you know why?
    networkPosition += velocity * lag * 1.71f;
    
  • @Tobias
    And one more little question :)
    Is it possible to be
    PhotonNetwork.Time < info.SentServerTime
    
    ?
  • Tobias
    Options
    I don't know why 1.71f. Might be a "magic number" which just seemed to work fine at some time?!

    Yes, PhotonNetwork.Time < info.SentServerTime is possible. The info.SentServerTime is the estimated server time from the other client and syncing the server time is not perfect.
  • @Tobias Yeah 1.71f is a magic number 🙃. And can I ask you a weird question?