Photon Player instantiate position
I am working on a game where there are 5 players joining a photon room, I'm instantiating the player position like this:
PhotonNetwork.Instantiate(Path.Combine("PhotonPrefabs", "Myplayer"), spawnPoints[spawnPicker].position, Quaternion.identity,0);
In the spawn points there are 5 different points being chosen at random, however doing that can have 2 players at the same position. Is there a way to not let a player instantiate if there is already an object there(another player) and check for a different spot. I think that raycast or physics.checksphere can work but I am not sure how to implement it here or if there is a better way to do this?
Thanks
Add a collider on each of the spawn points. A script on each:
public class Spawn point() { public bool Available=true;
public void OnCollissionEnter()
{
Available=false;
}
public void OnCollissionExit()
{
Available=true;
}
Then in your spawnPicker code, create an array of spawnpoints that are Available==true, choose your random point from that array. :)
Thank you so much for the reply @$$anonymous$$evRev. I added a script to all the spawn points (same script) and was able to see the bool for available change from true to false on collision. However I am having trouble getting the instantiate to check if the bool is true. How can I add that to the array of spawn points and check if it is true, the current array is public Transform[] spawnPoint.
Thanks again.
Answer by KevRev · Apr 27, 2019 at 04:45 PM
This should work:
List<SpawnPoint> tempSP;
foreach (SpawnPoint sp in SpawnPoints)
{
if (sp.Available) tempSP.Add(sp);
}
Then tempSP only contains available SpawnPoints that you can choose a random from.
Worked fine when doing it locally, but over the photon network it does not work as I have to somehow pass those variables as well. Thanks for the help though.
Your answer
Follow this Question
Related Questions
Keeping an object in a multiplayer scene, when a player joins. 3 Answers
C# Photon Networking - Preventing duplicate GameObjects from spawning on Join. 1 Answer
How can I change position of instantiate objects (clones)? 1 Answer
Game Object doesn't instantiate at Mouse Position 3 Answers
Wrong position (always 0,0,0) when Instantiate prefab. 1 Answer