Lag Compensation with Photon Unity Networking

Hello everybody! I’m trying to make a multiplayer 2D shooter game and I’ve decided on using Photon. The issue I’m having is that remote characters’ movements are choppy, but then if I lerp them they become floaty, and “glide” toward the ground (for lack of a better word) after a jump. Does anyone know of a way to mitigate this floatiness or of a better way to go about smoothing network movements?

This is the current script I have attached to the characters:

using UnityEngine;
using System.Collections;

public class NetworkPlayer : Photon.MonoBehaviour
{
    public Vector3 realPosition = Vector3.zero;
    public float speed = .1f;
	
	void Update ()
    {
	    if (!photonView.isMine)
        {
            transform.position = Vector3.MoveTowards(transform.position, realPosition, speed);
        }
	}

    void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.isWriting)
        {
            stream.SendNext((Vector3)transform.position);
        }
        else
        {
            realPosition = (Vector3)stream.ReceiveNext();
        }
    }
}

Thanks!
Bentley

Of course right after I ask the question I finally find an answer. This is my updated script. It seems smooth enough for my purposes and there are no more adverse lerp side effects. Hopefully someone else can find a use for this in the future.

using UnityEngine;
using System.Collections;

public class NetworkPlayer : Photon.MonoBehaviour
{
    public Vector3 realPosition = Vector3.zero;
    public Vector3 positionAtLastPacket = Vector3.zero;
    public double currentTime = 0.0;
    public double currentPacketTime = 0.0;
    public double lastPacketTime = 0.0;
    public double timeToReachGoal = 0.0;
	
	void Update ()
    {
	    if (!photonView.isMine)
        {
            timeToReachGoal = currentPacketTime - lastPacketTime;
            currentTime += Time.deltaTime;
            transform.position = Vector3.Lerp(positionAtLastPacket, realPosition, (float)(currentTime / timeToReachGoal));
        }
	}

    void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.isWriting)
        {
            stream.SendNext((Vector3)transform.position);
        }
        else
        {
            currentTime = 0.0;
            positionAtLastPacket = transform.position;
            realPosition = (Vector3)stream.ReceiveNext();
            lastPacketTime = currentPacketTime;
            currentPacketTime = info.timestamp;
        }
    }
}

thanks, when i saw your code i realised that i have a similar script from photon examples, that is almost the same, then i use it and goes perfect. no more lag.
Marcopolotutorial → NetworkCharacter.cs