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);
}