Trying to set spawn

Hello
In my game players are all spawning in the same time
And I would like to set spawn for each one
If the are 2 they gonna spawn back to back, if they are 5 they gonna spawn in star shape etc ...

Comments

  • Hi @M4TT,

    I guess the MasterClient triggers the spawning of the clients, am I right? If so the MasterClient can also define the spawn points based on how many players are in the room. You can get the number of players by using PhotonNetwork.room.PlayerCount. Having this information the MasterClient can for example notify each client and tell them their spawn position (and orientation). With this information each client can instantiate his prefab using PhotonNetwork.Instantiate(...). Another option might be the usage of the PlayerRoomIndexing component which is included in the PUN package. Using this each player has an 'index' which you can use to determine the correct spawn position.
  • Hi Christian
    Yep the masterclient make spawn all other players.
    How can I use that PhotonNetwork.room.PlayerCount to identify a player ?
    I tried that : PhotonNetwork.room.PlayerCount(1)but it's not working.

    For the second option, I didnt find thread about PlayerRoomIndexing, I really dont know how that works.
    Thanks for the help
  • bump
  • Do you know guys how that player.ID works ?
    If there is 3 players in the current room their playerID will be respectivly 1, 2, 3 ?

    If the second player leave the room, the 3rd player have still the playerID equal to 3 or it is 2 ?
  • PhotonNetwork.room.PlayerCount only returns the number of players that are currently in the room, it's not a function you can call. If you know how many players there are in the room, you also know how to place the spawn points: if you have two player for example, you know where they should spawn. The same applies for three or more players. Having this information the MasterClient can use for example the RaiseEvent function in order to notify each client about his spawn position. Like this:
    foreach (PhotonPlayer p in PhotonNetwork.playerList)
    {
        Vector3 spawnPosition = new Vector3(); // use the actual spawn position
        Quaternion spawnRotation = new Quaternion(); // use the actual spawn rotation, if you have to
        object[] eventData = new object[] { spawnPosition, spawnRotation };
    
        RaiseEventOptions options = new RaiseEventOptions() { TargetActors = new int[] { p.ID } }; // make sure to only send this event to a certain player
    
        PhotonNetwork.RaiseEvent(SetupSpawnsEventCode, eventData, true, options);
    }
    Make sure to implement an OnEvent callback to handle custom events like the one above. You can see how this works by taking a look at the RPCs and RaiseEvent documentation page. When a certain client now receives this event, the OnEvent callback function will be processed. Within this function the client can use PhotonNetwork.Instantiate(...) in order to instantiate his character with the help of the received information.
Sign In or Register to comment.