Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by BackslashOllie · May 09, 2016 at 03:05 PM · networkingspawnspawningspawnpoints

[UNET] Dynamically position NetworkStartPosition Gameobjects

Hi,

I am trying to dynamically change the position and amount of the NetworkStartPosition objects in my game scene depending on the max players set in the Network Lobby Manager. The idea is I will have matches that will allow either 2, 3 or 4 players and I want the spawn positions to be positioned around a large circle in my scene as per the image below respectively.

alt text

Can this be done on an Awake() method or OnStartServer() of a 'Spawner' object and then use the RoundRobin spawning method? I guess I could load a different scene depending on the Max Players but that doesn't seem like the best way of doing it.

I would really appreciate any help or suggestions.

spawnpositions.png (4.0 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image BackslashOllie · May 11, 2016 at 09:04 AM 0
Share

Does anyone have an idea of how I can instantiate NetworkStartPosition Gameobjects on level start and use the round robin spawn method to spawn my players?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by pankajb · May 09, 2016 at 05:21 PM

Something like this should work... just set number of players and call generateplayers() function somewhere

 int NumberOfPlayers;
 Vector3 playerPosition;
 float radiusOfOuterCircle;
 
 
 void GeneratePlayers(){  
         for (int i = 0; i < NumberOfPlayers; i++) {
 
                 float positionOfPlayerOnOuterCircle = i*1.0f / NumberOfPlayers;

                 //converting it to PI value Mathf.PI*2 ~= 6.28
 
                 float Angle = positionOfPlayerOnOuterCircle * Mathf.PI * 2;
         
             float X_position = Mathf.Sin (Angle) * radiusOfOuterCircle;
             float Y_position = Mathf.Cos (Angle) * radiusOfOuterCircle;

     Instantiate (yourPlayerPrefab, new Vector3 (X_position, Y_position, 0), Quaternion.identity);
 }
 }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image BackslashOllie · May 09, 2016 at 06:24 PM 0
Share

Hey, Thank you for the response. That is an awesome method that I will probably use, but it doesn't answer my specific question around UNET. Does anyone know if I can alter this method to instantiate NetworkStartPosition prefabs on the server before any clients connect?

avatar image
0

Answer by Kazhar · Feb 24, 2017 at 09:50 AM

I managed to do this by dynamically generating the NetworkStartPositions. Attach this script to an empty gameObject on your scene:

 public class DynamicStartPositions : MonoBehaviour
 {
     void Awake ()
     {
         int count = NetworkLobbyManager.singleton.maxConnections;
         for (int i = 0; i < count; i++) {
             float slice = 2 * Mathf.PI / count;
             float angle = slice * i;
             float x = Mathf.Cos (angle) * GameManager.arenaRadius;
             float y = Mathf.Sin (angle) * GameManager.arenaRadius;
             var go = Instantiate (new GameObject (), new Vector3 (x, y, 0.0f), Quaternion.identity);
             go.transform.parent = this.transform;
             go.AddComponent<NetworkStartPosition> ();
         }
     }
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

59 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Spawning help 1 Answer

Networking HLAPI Spawning Objects 2 Answers

Random spawnpoint where only one prefab can spawn! 1 Answer

[Help] How Do I Randomly Spawn Game Objects On Specific Coordinates? 3 Answers

how to "search" for a spawn point 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges