1

出于某种原因,其他玩家的动作“结结巴巴”。我知道这是人们在使用 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);
    }
}
4

1 回答 1

1

在玩家可能的旧位置和新位置之间进行平滑过渡,不要设置位置。您可以将 lerp 用于此方法或任何其他方法。

本视频教程介绍了光子网络的所有细节,包括如何处理口吃和您可能遇到的其他问题。视频教程播放列表

解决口吃的确切视频

它看起来像这样:

currentPosition = Vector3.Lerp(currentPosition, realPosition,0.1f);

currentPosition 是联网播放器在您的客户端上移动之前的位置,realPosition 是从网络接收到的您希望播放器所在的新位置。

于 2015-10-23T15:36:15.557 回答