2017-04-16 65 views
1

我正在使用您可以輸入的宇宙飛船創建多人遊戲。我正在使用光子多人遊戲。未同步的多人剛體運動(Photon)

正如你可以在下面的圖片中看到,我已經在PhotonView ship的Rigidbody中進行轉換,並且在Player上也是如此。
my PhotonView Settings

但是,當我進入船舶從其他玩家的看法看起來極端laggy(如果我推船它通常同步)。這是一個顯示問題的video

我的玩家使用固定關節連接到船上。
這裏是我的縮短代碼:

void Update() 
{ 
    //Raycast to check for ship 
    if ((Physics.Raycast(look, out hit, 9f) && hit.collider.tag == "Ship") 
    { 
     //set variables 
     shipObj = hit.collider.gameObject.transform.parent.gameObject; 
     ship = shipObj.GetComponent<SmallShipController>(); 

     if (Input.GetKeyDown(KeyCode.R)) 
     { 
      //check if ship is driven 
      if (!ship.driven) 
      { 
       driving = true; 
       ship.ChangeDriven(); 
       transform.position = ship.driverSeat.transform.position; 
       transform.rotation = ship.driverSeat.transform.rotation; 
       playersCamera.transform.position = ship.thirdPersonPosition.position; 
       playersCamera.transform.rotation = ship.thirdPersonPosition.rotation; 
       rb.detectCollisions = false; 
       rb.mass = 0; 
       rb.drag = 0; 
       rb.angularDrag = 0; 
       photonView.RPC("SetJoint", PhotonTargets.AllBuffered, shipObj.GetPhotonView().viewID); 
      } 
     } 
     if (driving) 
     { 
      if (Input.GetKey(KeyCode.A)) 
      { 
       ship.rb.AddRelativeForce(Vector3.left * ship.moveSpeed * Time.deltaTime); 
      } 
      if (Input.GetKey(KeyCode.W)) 
      { 
       ship.rb.AddRelativeForce(Vector3.forward * ship.moveSpeed * Time.deltaTime); 
      } 
      if (Input.GetKey(KeyCode.D)) 
      { 
       ship.rb.AddRelativeForce(Vector3.right * ship.moveSpeed * Time.deltaTime); 
      } 
      if (Input.GetKey(KeyCode.S)) 
      { 
       ship.rb.AddRelativeForce(Vector3.back * ship.moveSpeed * Time.deltaTime); 
      } 
      if (Input.GetKey(KeyCode.Space)) 
      { 
       ship.rb.AddRelativeForce(Vector3.up * ship.moveSpeed * Time.deltaTime * 0.5f); 
      } 
      if (Input.GetKey(KeyCode.LeftShift)) 
      { 
       ship.rb.AddRelativeForce(Vector3.down * ship.moveSpeed * Time.deltaTime * 0.5f); 
      } 
      if (Input.GetKey(KeyCode.Q)) 
      { 
       ship.rb.AddRelativeTorque(new Vector3(0, 0, Time.deltaTime * ship.moveSpeed)); 
      } 
      if (Input.GetKey(KeyCode.E)) 
      { 
       ship.rb.AddRelativeTorque(new Vector3(0, 0, Time.deltaTime * -ship.moveSpeed)); 
      } 
      if (Input.GetAxisRaw("Mouse Y") > 0.5f || Input.GetAxisRaw("Mouse Y") < 0.5f || Input.GetAxisRaw("Mouse X") > 0.5f || Input.GetAxisRaw("Mouse X") < 0.5f) 
      { 
       ship.rb.AddRelativeTorque(new Vector3(-Input.GetAxis("Mouse Y"), Input.GetAxis("Mouse X"), 0) * Time.deltaTime * ship.rotationSpeed); 
      } 
      if (Input.GetKey(KeyCode.C)) 
      { 
       ship.rb.velocity = ship.rb.velocity * 0.99f; 
       ship.rb.angularVelocity = ship.rb.angularVelocity * 0.99f; 
      } 
     } 
    } 
} 

[PunRPC] 
void SetJoint(int shipView) 
{ 
    shipObj = PhotonView.Find(shipView).gameObject; 
    shipObj.GetComponent<FixedJoint>().connectedBody = rb; 
} 

回答

0

我不會推薦這TECHNIC所有,如果您的播放器加入了一個物理對象,它應該完全接管了。讓這艘船成爲一個可以讓它的主人改變的場景對象,並且當一個玩家想要進入時它會成爲該船的擁有者。然後,您可以依靠管理管理並安全地控制來自各個玩家的航天器。

另外,我建議你使用光子論壇,你就會有更多的機會得到回覆。

再見,