Why is Photon so laggy?

I have a 2D game and i’ve been using Photon to make it multiplayer, however the movement of the other player on my player’s window looks very stuttering / laggy. Is this a problem with Photon because i’ve seen loads of posts with people having the same problem.

Here’s the code to move the player (simplified):

     public Rigidbody2D rb2D;



      public void Update () {

Vector3 targetPos = newVector3(369.1f, -188.9f, -0.1f);

rb2D.transform.position = Vector3.Lerp(rb2D.transform.position, targetPos, Time.deltaTime * 0.06f);

And here’s the code to view the other player:

public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
 {
if (stream.isWriting)
 {
//We own this player: send the others our data
stream.SendNext(rb2D.position);
stream.SendNext (rb2D.rotation);

 }
else
 {
//Recieve other player
realPosition = (Vector3)stream.ReceiveNext();





 }
 }

//Welerptowardsthis


publicvoidUpdate()
 {

if (!photonView.isMine) {
rb2D.transform.position = Vector3.Lerp (rb2D.transform.position, realPosition, 0.06f);
 }

Select a region close to your location (in PhotonServerSettings file) and check out the demos in the package.
Usually, things should be reasonably smooth. It depends a bit on what you do, need and expect.

Well just lerping from the newest positon/rotation is a very simple way of doing it.

This is a video for a game i created using PUN. Think its pretty smooth:

When i started out this post from Valve helped me a lot:
https://developer.valvesoftware.com/wiki/Source_Multiplayer_Networking

Good luck.

2 Likes

after research, this is my best solution, see here :