Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Spawning players in different teams separately

Discussion in 'Multiplayer' started by BenHowick, Jan 11, 2018.

  1. BenHowick

    BenHowick

    Joined:
    Jan 11, 2018
    Posts:
    10
    Hello
    I need a simple way of spawning red players on a red spawn point and blue players on the blue spawn point. I have no clue how to go about it. Is there anyway i can assign which NetworkStartPosition each player starts on using code by passing in the one I want it to spawn on from my own array. Any help would be very appreciated.
    Ben
     
  2. Benvictus

    Benvictus

    Joined:
    Sep 12, 2013
    Posts:
    87
  3. BenHowick

    BenHowick

    Joined:
    Jan 11, 2018
    Posts:
    10
    I’m not entirely sure what the difference between HLAPI is and Low level. If you could explain that would be brilliant and thank you very much. I’ve tried searching for custom spawning but nothing really came up. I’ll have a look and get back to you on what level API I’m working with
     
  4. BenHowick

    BenHowick

    Joined:
    Jan 11, 2018
    Posts:
    10
    Hello again. From what I’ve looked at I believe I’m using the HLAPI but I’m not too sure. I didn’t know that LLAPI was a thing until you said it. Will it be a problem that I’m using HLAPI or is this ok.
    Thank you and sorry for the unclarity
    Ben
     
  5. Benvictus

    Benvictus

    Joined:
    Sep 12, 2013
    Posts:
    87
    The (High Level API) HLAPI provides you with an easy-to-use system for managing players, networked objects and general aspects of your multiplayer game. The HLAPI includes the Network components that can be added via the inspector.

    The Low Level API (LLAPI) also known as the Transport layer allows you to code your own networking systems. It can be harder to work with if you are new to multiplayer game development but for its complexity, it gives you more freedom.

    It will not be a problem if you are using the HLAPI, you will be able to follow the manual to create your own custom spawners. It is also possible to create your own Network Manager, this will allow more customisation for your game project.

    Hope this helps.
     
  6. BenHowick

    BenHowick

    Joined:
    Jan 11, 2018
    Posts:
    10
    @BenStoneman yes thank you. That really helps. I’m using the HLAPI. I’ve got the player to spawn now using ClientServer.AddPlayer() then called a method on the player start to move it where I want. The problem is that it doesn’t apply it to the correct team. How would I get the player game object in the same function as where I spawn the player so I can assign a few variables? Can you please help with this. It would be much appreciated. Thanks
    Ben
     
  7. Benvictus

    Benvictus

    Joined:
    Sep 12, 2013
    Posts:
    87
    Hi @BenHowick

    I've not created my own custom team based spawner myself so I can only suggest a theory on how you can go about it.

    I will set up a team based spawner in a personal project to see what can be done. Are you able to provide me with the script you are using to spawn your players? Also, are you using a Custom made network manager script?

    Kind regards.
     
  8. BenHowick

    BenHowick

    Joined:
    Jan 11, 2018
    Posts:
    10
    I’ll go on my computer and see if I can send the code across if I remember to. I’ve got it so that I can set the team to the player as when the player spawns I’ve got it so that it picks up the variable then it should pass it to the server to set server wide but the [Command] I’ve got set up doesn’t seem to want to call.

    I’m using the network manager made by unity but spawning the player when the user selects which team they are in. Which then saves the team locally then the player calls a function that passes it over on start then tries to call the command.

    Also a quick question. Does the [Command] function need any specific requirements to be called?

    Thanks
    Ben
     
  9. Benvictus

    Benvictus

    Joined:
    Sep 12, 2013
    Posts:
    87
    @BenHowick

    I was able to create a basic team spawner that assigns the client a team when they connect and spawns their playerPrefab at the team's spawn point.

    I've attached it to this post. (used Unity version 2017.3.0f3)

    1. Import the package into an empty project.
    2. Add scenes to the Build Settings and network manager.
    3. Build and Test with multiple clients.

    I basically override the OnServerAddPlayer() function in a custom NetworkManager and change where the player spawns.

    Hope this helps!
     

    Attached Files:

  10. Benvictus

    Benvictus

    Joined:
    Sep 12, 2013
    Posts:
    87
    What is it you are trying to do and do you have some code?

    The only requirement should be that it is in a class that derives from NetworkBehaviour and is invoked on the player GameObject.
     
  11. BenHowick

    BenHowick

    Joined:
    Jan 11, 2018
    Posts:
    10
    Right thank you very much @BenStoneman ill have a look at it tomorrow. I’ve sorted out the command as I hadn’t called it from the player object. Thank you and I’ll get back to you tomorrow if I need more help. Thanks.
    Ben
     
    Benvictus likes this.
  12. Benvictus

    Benvictus

    Joined:
    Sep 12, 2013
    Posts:
    87
    @BenHowick

    Just checking to see if that package was helpful.
     
  13. BenHowick

    BenHowick

    Joined:
    Jan 11, 2018
    Posts:
    10
    Hi @Benvictus sorry. I haven’t really had chance to have a look at it yet. Now that it is the weekend I should have some more time on my hands so I should get a chance to have a look.

    One question though. Is there anywhere I can find the code for all the functions like AddPlayer() etc. This would be helpful so that I know what is being overwritten.
    Thanks
    Ben
     
  14. BenHowick

    BenHowick

    Joined:
    Jan 11, 2018
    Posts:
    10
    @Benvictus it is working for player one but not for the client connected to the server. none of the players show up. Thank you very much for your help but I've just managed to find a way to do it by passing a load of variables around.
    I'm now trying to add a respawning method which is proving harder than expected.
    Thanks again for the help.
    Ben.
     
  15. Benvictus

    Benvictus

    Joined:
    Sep 12, 2013
    Posts:
    87
    @BenHowick

    You are not overwriting any code that you need, it just means that we are extending/modifying the function. I'll get back to you after I search to see if the code for the functions is available.

    Is this in my unity package? Ensure that Auto Create Player is enabled on the Network Manager.
     
  16. BenHowick

    BenHowick

    Joined:
    Jan 11, 2018
    Posts:
    10
    @Benvictus right ok. That’s alright then. Override sounds like it isn’t running the other code. That’s all.

    Yeah it’s your package that isn’t working. I’m pretty sure that the auto create player is enabled as it works on the server player person
    Thanks
    Ben
     
  17. Sevenup

    Sevenup

    Joined:
    Nov 19, 2012
    Posts:
    5
    Hi @Benvictus this was a good example but how would you do this with respawn
    I have tried to implement this to player health script but without success.
    Grateful for help.