- Home /
Question by
unity_B5EB2DE23F3946B7E74F · Sep 13, 2021 at 10:24 AM ·
unity 5rigidbodynetworkingphoton
player facing lag issue or it is a sync problem ?
HI, I'm using photon Pun 2 and unity for my multiplayer game. when two players are join then they are facing lag problem. I don't know it is a lag or sync problem. Basically my player is on mouse control. player1 its working fine on my screen but player1 is facing lag on another screen.
here's my script:
PhotonView mpv; private RaycastHit hit;
mpv = GetComponent();
private void Update() { if (!mpv.IsMine || !controllable) { return; }
if (mpv.IsMine)
{
masterPlayer();
}
}
public void masterPlayer() {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, 10))
{
transform.position = hit.point;
//hitPosRelativeToZoneSpace = transform.InverseTransformPoint(hit.point);
}
if (PhotonNetwork.IsMasterClient)
{
if (transform.position.x <= -0.508f)
transform.position = new Vector3(-0.508f, transform.position.y, transform.position.z);
if (transform.position.x >= 0.503f)
transform.position = new Vector3(0.503f, transform.position.y, transform.position.z);
if (transform.position.z >= -0.064f)
transform.position = new Vector3(transform.position.x, transform.position.y, -0.064f);
if (transform.position.z <= -1.011f)
transform.position = new Vector3(transform.position.x, transform.position.y, -1.011f);
if (transform.position.y >= 0.005f)
transform.position = new Vector3(transform.position.x, 0.005f, transform.position.z);
}
else
{
if (transform.position.x <= -0.508f)
transform.position = new Vector3(-0.508f, transform.position.y, transform.position.z);
if (transform.position.x >= 0.503f)
transform.position = new Vector3(0.503f, transform.position.y, transform.position.z);
if (transform.position.z >= 1f)
transform.position = new Vector3(transform.position.x, transform.position.y, 1f);
if (transform.position.z <= 0.048f)
transform.position = new Vector3(transform.position.x, transform.position.y, 0.048f);
if (transform.position.y >= 0.005f)
transform.position = new Vector3(transform.position.x, 0.005f, transform.position.z);
}
}
Comment