我正在创建一个可以输入的太空飞船的多人游戏。我正在使用光子进行多人游戏。
正如你在下面的图片中看到的那样,我在PhotonView船上的Rigidbody,Transform和播放器上的相同。
但是当我进入船舶时,来自其他玩家的视图看起来极其迟钝(如果我推动它正常同步的船)。这是显示问题的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 :(得分:0)
我根本不推荐这种技术,如果你的玩家加入一个物理对象,它应该完全接管它。使船舶成为可以更改其所有者的场景对象,并且当玩家想要输入它时,使该玩家成为该船舶的所有者。然后你可以依靠管道管理并安全地控制各种玩家的航天器。
另外,我建议您使用光子论坛,您将有更多机会获得回复。
再见,
让