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 Conqueror1 · Jan 31, 2020 at 04:33 AM · spawningoverlapspawning problemsoverlapsphereoverlapping

Preventing Spawn Overlap With Spheres

Hello, I am new to Unity. I am unfortunately still quite confused on how to solve the overlapping of Spawned objects. Help would be greatly appreciated :) I have watched many tutorials and have read many answers but cannot seem to get it.

 public class PaintballSpawner : MonoBehaviour
 {
     public GameObject[] ballPrefabs;
     public float spawnRangeZ = 6;
     private float spawnInterval = 5f;
     private float startDelay = 2;
 
 
     // Start is called before the first frame update
     void Start()
     {
         InvokeRepeating("SpawnRandomPaintBall", startDelay, spawnInterval);
        
     }
     void SpawnRandomPaintBall()
     {
         Vector3 spawnPos = new Vector3(-1, 0, Random.Range(-spawnRangeZ, spawnRangeZ));
         int ballIndex = Random.Range(0, ballPrefabs.Length);
         Instantiate(ballPrefabs[ballIndex], spawnPos, ballPrefabs
             [ballIndex].transform.rotation);
     }
   }

 
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 sacredgeometry · Jan 31, 2020 at 10:50 PM 0
Share

Does that make sense/ help? Would you like an example?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by sacredgeometry · Jan 31, 2020 at 08:44 AM

Assuming you want to pack them regularly:

  • https://en.wikipedia.org/wiki/Sphere_packing

  • https://www.youtube.com/watch?v=CROeIGfr3gs


Assuming you just don't want them to touch surely its just a matter of checking that the ball is at least infinitesimally more than the radius apart from any of the other instances. Are you packing them regularly or wanting them to pack in an irregular way?


Another way to do pseudo random position (its a far less complex thing to compute too) it is to pack them regularly with padding and to use that padding as your randomness space.


I guess the question is what are you trying to make them look like i.e. what is the purpose of the randomness?

Comment
Add comment · Show 7 · 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 Conqueror1 · Feb 01, 2020 at 12:03 AM 0
Share

The balls are being spawned along a line at random positions. There are different types of these sphere objects they do different things depending on which one the player gets.

avatar image sacredgeometry Conqueror1 · Feb 01, 2020 at 12:04 AM 0
Share

The method still applies surely, or am I missing something?

avatar image Conqueror1 sacredgeometry · Feb 01, 2020 at 12:07 AM 1
Share

I just have no idea how to write it code wise to check if a sphere is there, and where to put it in the code lol.

Show more comments
avatar image sacredgeometry Conqueror1 · Feb 01, 2020 at 12:06 AM 0
Share

I mean either that or you could evaluate forwards through the list and store the position and size of the last item in it.

avatar image sacredgeometry Conqueror1 · Feb 01, 2020 at 12:11 AM 0
Share

I can write you an example of both with a description tomorrow

avatar image Conqueror1 sacredgeometry · Feb 01, 2020 at 12:13 AM 1
Share

It's ok :) I am going to watch more of the Unity course stuff. Thank you for offering.

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

120 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

Related Questions

How to avoid overlapping ground spawns?,How to avoid overlapped ground spawns 0 Answers

Objects overlapping at origin (0,0,0) (question about OverlapSphere?) 0 Answers

How to respawn player car in war track 1 Answer

Detect object outside overlapSphere 0 Answers

Question about Unet and spawning 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