Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 RayDawg · Jan 15, 2014 at 10:26 PM · instantiateprefabspawningspawnpoints

How do you spawn multiple prefabs within a certain distance from each other from one spawn point?

Say I have four spawn points, and I want each spawn point to instantiate a random amount of rigidbody prefabs within a certain range of each other. I can currently instantiate one prefab per spawn point, so how would I go about doing this?

Comment
Add comment · Show 2
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 robertbu · Jan 16, 2014 at 12:28 AM 0
Share

-Generate all within a certain distance of the spawn point, or is the distance between each Instantiated object the important thing?

-Are you looking for a formation like a grid, or spawned in a circle, or are you looking for random placement?

-Is this 2D (i.e. on a plane), or 3D (within a sphere).

avatar image RayDawg · Jan 16, 2014 at 12:52 AM 0
Share
  1. Generate a random amount of prefabs within a certain distance of a spawn point.

  2. Circular formation

  3. This is on top of a 2d plane $$anonymous$$G spawning 3D prefabs on a gameobject named "ground"

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by HappyMoo · Jan 16, 2014 at 02:05 AM

Here's some code. Not tested in unity, so might include syntax errors, but you get the idea.

 Vector3 spawnMidPoint = new Vector3(5,0,10);
 int num = Random.Range(3,10);
 float radius = 10;
 float pi2 = 2*Mathf.PI;
 for(int i = 0; i<num; i++)
 {
    Vector3 pos = spawnMidPoint + new Vector3(Mathf.Cos(i*pi2/num)*radius,0,Mathf.Sin(i*pi2/num)*radius)
    Instantiate(prefab, pos, rot);
 }
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 RayDawg · Jan 16, 2014 at 05:37 PM 0
Share

This worked fine, thank you!

avatar image
0

Answer by Deon-Cadme · Jan 16, 2014 at 12:39 AM

You calculate the position for each new instance of an object that you are spawning.

A good practice is also to make a collision check before spawning, just to make sure that no object ends up halfway in a wall or something. Another trick is also to define a radius or area around the spawn point where the objects are allowed to appear. That way, you can avoid a lot of collision checks.

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

20 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

Related Questions

How do I spawn an object under another moving object at random in C#? 1 Answer

How to spawn a new prefab when the last one was destroyed?? 2 Answers

Prevent object from spawning at a spawn point twice in a row? 3 Answers

prevent object from falling to the left side when instantiated (spawned) ? 1 Answer

SOLVED : Adding and retrieving instantiated objects from Array 1 Answer


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