Set local player position based on data tracked only on masterclient

Options
A question about best practices and client/server responsibilities when spawning/positioning players:

When each client connects, I PhotonNetwork.Instantiate the local player prefab as usual. There are two teams, each has a spawn point and I want to allocate each new player, alternately, to a team. Is it best to track such team allocation (and player position) on the masterclient only? It seems like this should be coordinated centrally.

If so, when I create the player locally, I don't know where to position them until the masterclient has put them on a team. What's the best way to handle that? Should I (can I) allow the masterclient to move players around? Do I send an RPC call back to the client to tell them which team they are on and what their starting position is? It seems quite complicated :-). Just want to check if there's a better/easier way.

Thanks!

Comments

  • should have said that I can see how masterclient can move client players - I really just need to ensure it's the BEST thing to do.
  • Hi @NotQuiteSmith,

    Is it best to track such team allocation (and player position) on the masterclient only?


    I don't know if this is the best way, but at least an option which works. Another option would be to allow each client to select a team on his own. Since you might run into an uneven number of team members, you would have to think about some kind of 'limitation' in this case. For any usage of teams, I would recommend you taking a look at PunTeams script included in the PUN package. This is a pre-implemented solution for teams.

    I don't know where to position them until the masterclient has put them on a team. What's the best way to handle that? Should I (can I) allow the masterclient to move players around? Do I send an RPC call back to the client to tell them which team they are on and what their starting position is?


    This would work. I think I already have given you that hint before. However I though about another solution, that will hopefully also work: whenever OnPhotonPlayerConnected is called on the MasterClient, he can instantiate the prefab for the new player (already using the correct spawn position) and transfer ownership to the new player by using something like GetComponent<PhotonView>().TransferOwnership(newPlayer.ID);.
  • Thanks! I went with the RPC call back - but that ownership transfer is a great idea too.