出于某种原因,其他玩家的动作“结结巴巴”。我知道这是人们在使用 Photon 时遇到的常见问题,所以想知道是否有人知道我该如何解决?
这是我的玩家移动代码:
public float SmoothingDelay = 5;
public void Start()
{
GetComponent<SmoothSyncMovement>().enabled = true; //This is the name of this script
}
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
{
//Network player, receive data
correctPlayerPos = (Vector3)stream.ReceiveNext();
}
}
public void Update()
{
if (!photonView.isMine)
{
Vector2 playerMovement = rb2D.position + velocity * Time.deltaTime;
rb2D.MovePosition(playerMovement);
}
if (photonView.isMine)
{
Vector2 playerMovement = rb2D.position + velocity * Time.deltaTime;
rb2D.MovePosition(playerMovement);
}
}