Positioning players as they join a room/scene

Options
Hi,
I have a mechanism where a group of players are all transferred to a new room/scene at the same time (they all get an RPC call to disconnect and reconnect to a specified room). Could someone help with these questions below?:

1) I'm assuming (hoping) that whenI send them all to the room, that one will become the masterclient and all the subsequent players will trigger OnPhotonPlayerConnected on that master client? i.e. There are no "contention" issues where you get 2 masterclients or that the other players join so quickly that the master client "misses" some connection events, etc. Just want to check!
2) Are there any examples where the masterclient takes each incoming player and moves them to a position on the map? i.e. how do I take the PhotonPlayer object supplied by OnPhotonPlayerConnected and get the corresponding gameObject so I can move it?

Thanks!

Comments

  • Hi @NotQuiteSmith,

    to the first question: Yes, this works. The first player who enters the room becomes the one and only MasterClient (this role can change during the lifetime of the room). This MasterClient will process the OnPhotonPlayerConnected callback for each client that joins after him, he won't miss any of these events.

    To the second question: if you are using the OnPhotonPlayerConnected callback it already has a reference to the new PhotonPlayer. You can use this reference for example, to raise an event just for this player in order to tell him his new position. Like this:
    public void OnPhotonPlayerConnected(PhotonPlayer newPlayer)
    {
        Vector3 position = new Vector3(); // use a specific position here
        object[] eventData = new object[] { position };
    
        RaiseEventOptions options = new RaiseEventOptions() { TargetActors = new int[] { newPlayer.ID } };
    
        PhotonNetwork.RaiseEvent(DefineEventCode, eventData, true, options);
    }
    Make sure to implement an OnEvent callback handler in order to process custom events. Within this OnEvent callback handler the client can either instantiate his character if that is necessary or just update the position of his character. To see how you have to implement this callback I would recommend you taking a look at the RPCs and RaiseEvent documentation page.
  • Thank you!