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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
1
Question by KurtK · Sep 27, 2013 at 01:42 AM · instantiatespawningrts

Spawning multiple objects in same area without intersecting each other

I want to spawn/instantiate a group of objects around a spawner. The problem is, I don't want them to occupy the same space. If I use rigid bodies and colliders and let the physics system figure out the position (by spawning them all on top of each other) then they fly off in two directions due to some force applied.

To help visualize what I'm trying to accomplish, picture the following horrible ASCII art:

 A = spawner
 B = unit 1
 C = unit 2
 D = unit 3

 Scenario 1:
 BBCC
 ABCC
 BBCC
 CCCC

 Scenario 2:
 
   CCBBBA
   CCBBB
   CCBB
   CCBB

  DDA
  DD

The goal is to instantiate these objects as a group, multiple objects acting as one. The problem I have is I have no idea how to determine what areas are free. I'm working with cubes so I don't know if OverlapSphere will work properly as it might create too big of gaps between the units. If you need more detail from me or better descriptions of the goal, let me know and I'll see what I can do. I've spent the past few hours hunting through documentation, tutorials and examples trying to figure out how to accomplish this but it seems the only answers I've found are manually placing them in the editor or spawning them as a circle (which ignores existing objects).

I was hoping that by using rigid bodies/colliders I would let the physics engine sort of nudge them into an orderly position, but that didn't exactly go as planned. Another idea was to get the position and size of the spawner and spawn a unit by doing a raycast in a cardinal direction, finding an empty space and then placing the unit there. Then to spawn the next unit, I'd raycast from the first unit and find an empty space. The problem with that is I don't know if that kind of raycasting is expensive and what to do if the spawner is completely surrounded (the units should still spawn, see the C units in Scenario 1). The only thing that should prevent the units from spawning would be a hard limit on how many can be on the map or in a highly unlikely scenario, if there's no room on the map.

If the ASCII art above isn't descriptive enough, I'll throw something together in paint. I'm not an artist, sadly, so I'm working with programmer art (or lack thereof).

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

0 Replies

· Add your reply
  • Sort: 

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

15 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

Related Questions

Insantiate object to parent without changing scale? 0 Answers

instanstiate Spawns more then one objec 0 Answers

Instantiate a Gameobject and AddForce to it (Rigidbody2D) 1 Answer

Checking if object intersects? 1 Answer

Gap Between Scrolling Background Objects 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