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 TheEmeraldRuby · Jun 26, 2018 at 07:34 PM · instantiateprefabspawnspawningspawner

How to Make an Expanding Spawn Area for Prefabs?

Hello, everyone. I am making a game where I want some prefab cubes to be continuously spawned around a bigger cube; kind of like the rings of a planet. The problem is: the bigger cube is continuously growing in size, therefore more objects must be spawned around a larger area/circumference. How would I do this? (possibly an expanding ring shaped spawn area?) Thanks!

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by ahstein · Jun 26, 2018 at 08:21 PM

Define your spawn region in polar coordinates (radius, angle) around the center of your cube. Spherical coordinates if you're working in 3D. You can easily expand the radius to be either the size of the cube times some factor or plus some factor. You can spawn at random angles or according to some pattern.

You'll need to include a conversion from polar/spherical coordinates to Cartesian coordinates, though.

  Vector2 PolarToCart (float r, float theta) {
          return new Vector2(r * Mathf.Cos(theta), 
 `                         r* Mathf.Sin(theta));
     }
     
     Vector3 SphericaltoCart (float r, float theta, float phi) {
          return new Vector3(r * Mathf.Cos(theta)*Mathf.Sin(phi), 
                            r*Mathf.Sin(theta)*Mathf.Sin(phi), 
                            r*Mathf.Sin(phi));
     }


Comment
Add comment · Show 4 · 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 TheEmeraldRuby · Jun 27, 2018 at 02:55 PM 0
Share

@ahstein so how exactly would I define all this stuff and implement it into the game? i'm rather new to c#, so some details or example code would be nice :)

avatar image ahstein TheEmeraldRuby · Jun 27, 2018 at 03:28 PM 0
Share
 // attach this to the parent object
 class Spawner : $$anonymous$$onobehavior {
      public GameObject prefabToSpawn;
      public float parentSize; // if you changing the size of the cube using it's transform's scale, this is unnecessary, you can just use that ins$$anonymous$$d. 
 
      // spawns prefabs every 30 degrees in a circle around the parent. The radius of the circle is 20% larger than the parent's size.
      void SpawnInCircle() {
           float radius = parentSize * 1.2f;
           for(int theta = 0; theta < 360; theta += 30) {
                Vector3 location = SphericalToCart( radius, theta, 0);
                GameObject newSpawn = Instantiate(prefabToSpawn, location, Quaternion.identity);
                newSpawn.transform.parent = transform;
           }
      }
 
      Vector3 SphericalToCart (float r, float theta, float phi) {
           return new Vector3(r * $$anonymous$$athf.Cos(theta)*$$anonymous$$athf.Sin(phi), 
                             r*$$anonymous$$athf.Sin(theta)*$$anonymous$$athf.Sin(phi), 
                             r*$$anonymous$$athf.Sin(phi));
      }
 }


avatar image TheEmeraldRuby ahstein · Jun 30, 2018 at 03:45 PM 0
Share

@ahstein so how would I replace parentSize with transform.localScale?

Show more comments
avatar image
0

Answer by Trevdevs · Jun 27, 2018 at 03:00 PM

If these cubes are purely aesthetic and don't need to be interacted with you could use a particle system and under the velocity tab play with the orbital velocity.

Here's a video that demonstrates it :)

https://www.youtube.com/watch?v=J3vFCpZ-Ims

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

128 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

instatiates at a bad position 1 Answer

How Do I Add An Instantiated Object To An Array? 3 Answers

How to prevent multiple spawns from a single spawn point? 1 Answer

Having Trouble with Instantiating an object on an axis 2 Answers

How would I create a script that spawns objects more frequently as time goes on? 3 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