Help me with photon lags i can t find probleme

Options
Hello
Iam working with Unity 2017 Personal and trying android jumping platformer game
but i dont know why my game lagging (Players positions,and Jumping animations too...)

Here is lagging proof:


Okey is possible to downgrade the lags? or what iam doing wrong?

Here is my photon view component



This is my Sync Script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Sync : Photon.PunBehaviour {



private Animator m_Anim;
private bool isRunning;
private float Speed;


private Vector3 realPosition;
private Quaternion correctPlayerRot;

// Update is called once per frame
void Update()
{
if (!photonView.isMine)
{
transform.position = Vector3.Lerp(transform.position, realPosition, Time.deltaTime * 5);
transform.rotation = Quaternion.Lerp(transform.rotation, this.correctPlayerRot, Time.deltaTime * 5);
m_Anim.SetBool("Ground",isRunning);
m_Anim.SetFloat("Speed",Speed);
}
}

void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
// We own this player: send the others our data
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
stream.SendNext(m_Anim.GetBool("Ground"));
stream.SendNext(m_Anim.GetFloat("Speed"));

}
else
{
// Network player, receive data
this.realPosition = (Vector3)stream.ReceiveNext();
this.correctPlayerRot = (Quaternion)stream.ReceiveNext();
isRunning = (bool)stream.ReceiveNext();
Speed = (float)stream.ReceiveNext();
}
}



// Use this for initialization
void Start(){
m_Anim = GetComponent();
}


}



Thanks for any help




Comments

  • try taking the player transform off of the observed components and just observe the player sync script
  • W33v3ly
    W33v3ly
    edited September 2017
    Options
    It is same but without right/left facing iam trying change this

    transform.position = Vector3.Lerp(transform.position, realPosition, Time.deltaTime * 5);
    transform.rotation = Quaternion.Lerp(transform.rotation, this.correctPlayerRot, Time.deltaTime * 5);

    to this

    transform.position = Vector3.Lerp(transform.position, realPosition, Time.deltaTime * 30);
    transform.rotation = Quaternion.Lerp(transform.rotation, this.correctPlayerRot, Time.deltaTime * 30);

    But without any effect

    I thing somewhere here is a problem when player is jumping then lagging was started and this show in console:

    IndexOutOfRangeException: Array index is out of range.
    PhotonStream.ReceiveNext () (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonClasses.cs:1066)
    PhotonView.DeserializeComponent (UnityEngine.Component component, .PhotonStream stream, PhotonMessageInfo info) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:387)
    PhotonView.DeserializeView (.PhotonStream stream, PhotonMessageInfo info) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:363)
    NetworkingPeer.OnSerializeRead (System.Object[] data, .PhotonPlayer sender, Int32 networkTime, Int16 correctPrefix) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:4225)
    NetworkingPeer.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2503)
    ExitGames.Client.Photon.PeerBase.DeserializeMessageAndCallback (System.Byte[] inBuff)
    ExitGames.Client.Photon.EnetPeer.DispatchIncomingCommands ()
    ExitGames.Client.Photon.PhotonPeer.DispatchIncomingCommands ()
    PhotonHandler.Update () (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:157)

    But i dont know what now
    I fix it with comment all Animator code but still lagging
  • try turning off that sync script and use Cubeinter script from photon demo, the movement should be smooth, if its not its something else and not to do with the sync script

    if its smooth with the cube inter script add the animations to cube inter script and see if it still works

  • W33v3ly
    Options
    Okey thanks cherrybombe but i fix it after hours the main and only problem has been in the my player have a rigidbody2D component which dont sync.This caused a lags on jumping.I only add Photon Rigidbody2D view then add it to observe and now all working without any problems.