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 jypelton · Mar 12, 2012 at 03:24 AM · instantiatepositionobjectopen

Find open position

I would like to instantiate a new object at a point that is not occupied by another object. Is there an existing method for acheiving 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 syclamoth · Mar 12, 2012 at 03:40 AM 1
Share

This depends entirely on several things that you haven't told us- for example, is there a finite number of positions that objects can occupy? Are all the objects the same size and shape? Do the objects have colliders? Is there a limit to the area in which they must spawn?

avatar image jypelton · Mar 12, 2012 at 03:58 PM 0
Share

Thanks syclamoth. This is the same as any game with a base that creates vehicles. The objects are of variable size and shape. They have rigid bodies now, but can have colliders. There is not a finite number of positions that they can occupy - theoretically anyway. There is not a limit to the area in which they can spawn.

Objects will spawn around a central object (base) on a plane, although I may change that to a terrain. So they should spawn as close to the central object as possible without overlapping another object excluding the central object (they may be spawned inside the base and then move to an open position, but I'm ok with spawning the at the open position for now).

1 Reply

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

Answer by syclamoth · Mar 12, 2012 at 04:05 PM

Finding an 'open space' can be quite difficult, as there are a lot of things to take into consideration. One way of doing this would be to use Physics.CheckSphere on random points until an empty one is found- however, this isn't guaranteed to produce a result in a finite time, and neither does it find the closest available spot (which, I should mention, makes things even harder).

If your objects have rigidbodies and colliders, you can just spawn it in any location, and let the physics engine sort out the arrangement of the objects. If you're using some kind of pathfinding / crowd simulation, you could adapt that to this problem as well.

Basically, you can use Physics.CheckSphere to make sure that there are no colliders in an area, but it's hard to know exactly what points you need to check.

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 jypelton · Mar 12, 2012 at 04:57 PM 0
Share

Thanks again.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to stop objects spawning on top of each other 2 Answers

Object won't instantiate at parents position(solved) 2 Answers

Not instantiating prefab in the right place after 2017 update 2 Answers

Random array issue C# 2 Answers

Destroy and instantiate far objects 2 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