- Home /
Trying to spawn players in multiple starting positions
Hi, I am a student. My group is developing a game in which the main players start in different areas (within their own respective maze). We are all new to Unity. I have done the Multiplater Networking tutorial.
The issue appears to be that the Network Manager only has one Player Prefab spot.
I considered placing each play's maze in its own scene, but then I do not know how to concurrently run those multiple scenes at once.
I also considered simply adding the other players in the Registered Spawnable Prefabs section in the Network Manager (if I kept all mazes in one scene).
Or finally, I was thinking about having each player start in the same screen where there are doors that will transport them to the starting location of their maze (with each door only allowed to be used once).
If anyone could please direct me to a tutorial, or give me some advice, I would really appreciate it.
starting with a multiplayer project as a student is a very bad idea. multiplayer gets very complicated and you will get less answers here. If you are a student you should start with completing a one player version of your game first!!!!!!!
There are two ways for you to achieve this:
You have a static List That are stored in your project and you pull a random number from your host and get that index sent to all the client machines.
You can send the actual transform itself to all the clients.
I don't fully understand what your saying with the "Each scene" I don't know if you fully understand how networking works, with all due respect. Try and explain it a little better for me and I will help you out with what you're looking for.
As @toddisarockstar said, it is a bad idea to start your first project as mutliplayer.However, without getting into the code, what I usually do is when the first player enters the room, he sends his player ID, which I always start at 1, when other players receive it, they log the users network ID and the player ID, then adds to the number and sends his own info, eventually every player will of sent out their info and continued adding to the number. If you get two players with the same ID, you check the time it was sent, pick the first guy, and send back to the other player that his new number is that + 1. Alternatively you can just random roll on who gets to be what number. It isn't always an option to say the host gets to be 1, since APIs like GPGRT$$anonymous$$ don't actually have a "host", its up to you.
After all players have been declared, you can then assign each player to a spawn point, or an offset of the spawn point. if you want specified spawn points, I would use a GameObject[] where each index corresponds to the according players position. So if you start your IDs at 0, then you can just spawn the players are their ID index.
I hope this helped.
P.S. One of the biggest things you need to be aware of is latency and device hardware, so if a user has a slower device, it may take him longer to load in and such. To account for this, you usually need to create a ready check system where the match doesn't start until all players declared they are ready. The ready checks and ID's $$anonymous$$UST be sent through reliable channels. Sometimes I even create a callback to declare the ready check was received, and if the callback never arrives, then I resend the data every X often.
You need to create a script which derives from Network$$anonymous$$anager. Then you need to create a list of game objects to be used when spawning. You will need to override the spawning code. I may post the answer once I get back home, but for now you can take a look at the code of my multiplayer project
Answer by ryannotfound404 · Jun 12, 2017 at 09:11 AM
Have you reviewed the Merry Fragmas series? https://unity3d.com/learn/tutorials/topics/multiplayer-networking/merry-fragmas-30-multiplayer-fps-foundation
Watch the video, from at least 19:00
Network Manager > Spawn Info: set Player Spawn Method to "Round Robin"
This would set them to all different locations, but may give you some food for thought.
Your answer
Follow this Question
Related Questions
MLAPI spawn player prefab 2 Answers
Unity networking tutorial? 6 Answers
Unet: Discern between user disconnection and connection lost 1 Answer
UNet - Connecting and Testing a 'choose your character' scenario 0 Answers
Custom network ID values 0 Answers