unity – How to get good movement synchronization in a networked game (action/shooter)


I’ve spent the last two days trying to get good movement interpolation with Photon in Unity but I can’t get anything that I’m happy with. I’ve tried several methods but none satisfied me. My understanding is that I better use some kind of interpolation (as opposed to extrapolation/dead reckoning) because in my game the players can change direction fast.

I’ve tried lerping between the current position and the last received authorized position, I’ve tried lerping between the old and the new authorized position, but nothing gives me the right amount of responsiveness + smoothness. What can I do?

Sample code:

public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
    if (stream.IsWriting) //do we have authority over this object?
    {
        stream.SendNext(transform.position);
        stream.SendNext(transform.rotation);
    }
    else
    {
        newNetworkTime = Time.time;
        oldPosition = transform.position;
        oldNetworkPosition = networkPosition;

        networkPosition = (Vector3)stream.ReceiveNext();
        networkRotation = (Quaternion)stream.ReceiveNext();
    }
}

void RemoteMovement()
{
    float t = 1.0f - ((newNetworkTime + interpolationPeriod - Time.time) / interpolationPeriod);

    transform.position = Vector3.Lerp(oldPosition, networkPosition, t);
    transform.rotation = Quaternion.Lerp(transform.rotation, networkRotation, Time.deltaTime * movementSpeed);
}