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
1
Question by bateleur · Dec 17, 2010 at 04:07 PM · collisionphysicscreate

Checking for Collisions Before GameObject Creation

Suppose that I want to create an object (or set of objects) only if the space they would occupy does not contain any other objects. How can I check for this?

(I'm aware of Physics.OverlapSphere(), but that's only any use if the GameObjects are all spheres, or at least have spherical colliders, which is not in general the case.)

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 Jesse Anders · Dec 17, 2010 at 06:46 PM 1
Share

Where does it say that OverlapSphere() requires the game objects to have spherical colliders? (According to the docs at least, the colliders aren't considered at all; rather, the bounding volume for the collider is used.)

avatar image bateleur · May 13, 2011 at 06:28 AM 0
Share

The object I'm creating has to be spherical, otherwise the check won't match what I'm trying to test!

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by _Petroz · Dec 17, 2010 at 10:09 PM

I think the best way to do it would be to have an invisible instance which you position at the location, and check if that invisible instance is colliding. If that instance isn't colliding then create a real instance. That allows you to create any shape/size collider you need.

Comment
Add comment · Show 3 · 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 Eric5h5 · Dec 17, 2010 at 11:24 PM 0
Share

You'd have to wait until the next physics frame to get the results, though, and it would potentially affect the other objects in the scene, which may or may not be acceptable depending on what you're doing.

avatar image bateleur · Dec 19, 2010 at 10:20 AM 0
Share

Unfortunately the "affecting other objects" part isn't acceptable. (A one physics cycle delay is fine, though.)

avatar image eedok · Dec 24, 2010 at 07:11 AM 0
Share

Couldn't you make it a trigger so it doesn't affect other objects?

avatar image
0

Answer by netatti · May 12, 2011 at 01:50 PM

I had a similar problem and resolved it using this

Physics.OverlapSphere(position, radius);

That'll return an array of Colliders that are intersecting or touching a Sphere at position with the given radius.

Other functions (like Physics.CapsuleCastAll) also sound very promising, but didn't work out for me. For some reason they didn't return collisions properely.

hth

Comment
Add comment · Show 2 · 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 bateleur · May 13, 2011 at 06:28 AM 0
Share

As mentioned in the original post, that only works for checking a sphere, so isn't very useful to me.

avatar image netatti · May 16, 2011 at 07:49 AM 0
Share

oh, sorry for not reading carefully. In my case I'm respawning a human character, which is also not spherical. But I set the radius large enough to avoid collisions most likely and I'm fine with that.

avatar image
0

Answer by alior · Nov 18, 2016 at 07:44 AM

Instantiate prefab but make all collider triggers. Check for trigger state. .... Profit!

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

1 Person is following this question.

avatar image

Related Questions

Prevent rigidbody being affected by character controller 2 Answers

Rigidbodies won't collide if mass difference is too high 0 Answers

Detailed terrain mesh collision 1 Answer

Problem with custom raycast2D collision detection system. 1 Answer

Creates not colliding with anything besides character controller when made rigid (in AngryBots) 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