Spawn players in unique places Please helpppp

Options
Ok i give up...thats why im posting this. I just cant figure out why my variables arent updating.

Currently this is how i am spawning the player:

spawnPoints = GameObject.FindGameObjectsWithTag("pSpawnP");
bool spawned = false;
while(!spawned){
int randS = Random.Range(0, spawnPoints.Length);
if(spawnPoints[randS].transform.childCount == 0){
GameObject insPlr = PhotonNetwork.Instantiate(playerPrefabE[selectedModel].name, spawnPoints[randS].transform.position, spawnPoints[randS].transform.rotation, 0);
insPlr.transform.SetParent(spawnPoints[randS].transform);
spawned = true;
}else{
spawned = false;
}
}

In my scene i have spawn points with photon views. When i spawn my player i check if a spawn point has a child and if it doesnt i spawn it and set that spawn point as the parent to my player. However when other players join they cant see that i am a child of the spawn point. The spawn point isnt synchronizing its children.

I also tried making a script for the spawn points and setting a bool to false. When i spawn the player i check if its false and then spawn the player and set it to true. I set this variable using a PUNRPC call, but when other players join the game they cant see the updated variable. I tried using an int and setting it to 0 when not occupied and 1 when occupied but when players enter they cant see it update. I also tried putting the variable in PhotonOnserializeView and i tried different observe options and still when players enter the match they cant see the updated variable, just the default.

Am i missing something? How do i sync a variable for players that havent joined the match yet, or how can i sync a spawnpoint and the child object to new players entering the match.

thank you,
chris

Comments

  • LivingUniverse
    edited January 2017
    Options
    okokokokokok i found out a few things after testing the occupied variables. if i set them with rpc actually do sync to players that enter however this is where it gets super tricky. When the player spawns in the game i use an rpc called spawn player when new players spawn they run the rpc because the rpc is buffered for all new players. They spawn in faster than the variable occupied gets synced up. I debugged the variables occupied at the time the player spawns in and they come out all false, but wait some milliseconds later and the ones occupied debugged out as true so i put in a spawn button to try the spawn the players when they want. If the first person connects his network manager gets updated, the other players that come in their manager doesnt get updated and they cant spawn. If the player that created the room which is the masterclient leaves instantly the other player gets his network manager updated and he can spawn in i cant believe how frustrating this is. If i cast rpc they spawn in faster than the variables are synced and i cant seem to delay the rpc like a second or something and if i dont use an rpc the network managers for other players dont get updated some reason.

    I think if i am able to delay the buffered rpc for new players for like a second it will work. How do i delay it??
  • LivingUniverse
    edited January 2017
    Options
    I finally came up with a solution that works after many many hours...

    spawn the player in using a random number generator 2000 - 3000 pos x y and z, 1 out of a trillion chance the players are going to have the same pos... or you can just turn mesh off, use a smaller number and turn it on in the next step: I added a spawn/ready up button and since the player is spawned the spawnpoint variables that were already set had time to be synced and then when you press the button it searches the spawnpoints, finds a free one and then i use two rpc calls, 1 that sends the view id of the player gameobject to the spawnpoint and search for the gameobject according to the view id and then turn bool occupied to true. In the update i have if(occupied && occupant != null) run and rpc to turn occupied to false. So if players leave it frees up the spawn point. The spawn/ready up button also sends an rpc notifying all players that the player is ready, when all players are spawned and ready the match begins.


  • o0heza0o
    Options
    hmm, i have been trying this for hours on end :/ on my end it doesn't work but probably because i haven't used the code properly :/