Help with De-synced Positions

Hey guys. I'm really lost here and I feel super stuck with my situation and I'd rather just explain how I currently have my scene setup.

I have a GameObject with a 'Photon Network Controller' attached, and `OnJoinedRoom()` is called with a `InstScene()` function which looks like below.

    GameObject[] allGuns = GameObject.FindGameObjectsWithTag("Guns");

    foreach (GameObject gameObj in allGuns)

    {

      if (gameObj.GetComponent<PhotonView>())

      {

        GameObject gameEquipment = null;


        if (PhotonNetwork.IsMasterClient)

        {

          gameEquipment = PhotonNetwork.Instantiate("Equipment/" + gameObj.name, gameObj.transform.position, gameObj.transform.rotation);

        }

      }


      Destroy(gameObj);

    }


    if(GameObject.FindGameObjectWithTag("GameController"))

    {

      Transform oldGameControllerPosition = gameController.transform;


      Destroy(GameObject.FindGameObjectWithTag("GameController"));

      if(PhotonNetwork.IsMasterClient)

      {

        GameObject newGameController = PhotonNetwork.Instantiate("Game Controller", oldGameControllerPosition.position, oldGameControllerPosition.rotation);

        gameController = newGameController.GetComponent<GameController>();

      }


      playerPrefab.GetComponent<PlayerController>().gameController = gameController;

    }


From what I can tell, this setup is okay.


In my PlayerController, I have a 'OnClick' function which is called via the Event System.


  [PunRPC]

  void OnClick()

  {

    RaycastHit hit;


    if(Camera.main)

    {

      Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

      if (Physics.Raycast(ray, out hit))

      {

        if (hit.transform != null && hit.distance <= 2.5f)

        {

          hit.transform.SendMessage("Click", SendMessageOptions.DontRequireReceiver);

        }

      }

    }

  }


When a non-master client enters the room and picks up a gun, on their screen it appears positioned correctly but on the master client it is still sitting where it originally was. However, the non-master client is still able to 'toggle' the gun off and on, indicated by the emissions that take place when toggled. Indicated with this code:


  void Click()

  {

    playerController = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerController>();

    print(playerController.name);


    handCube = playerController.GetRightHand();


    this.tag = "HeldGun";

    GetComponent<BoxCollider>().enabled = false;

    GetComponent<Rigidbody>().isKinematic = true;

    transform.parent = handCube.transform;

    transform.position = handCube.transform.position;

    transform.rotation = handCube.transform.rotation;


    transform.localRotation = Quaternion.Euler(180, 0, 180);

    transform.localPosition = new Vector3(1.8f, -0.2f, -1.7f);


    this.tag = "HeldGun";

    isPickedUp = true;

  }



All of the guns have a PhotonView attached to them along with a PhotonTransformView, and I'm honestly just at a loss as to what is going on. The non-master client can see the master client's gun positioned correctly.

Answers

  • Bump. Appreciating an update here.

  • Bump.

  • Please don't bump.

    Please use the formatting options on the left side of the input box, when you edit text.

    Can you provide a short summary of what the problem is? The code currently makes it hard to grasp the problem.