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 SGPascoe · May 29, 2012 at 02:35 AM · collisiongameobjectinstantiateproceduralcheck

checking collisions before instantiating (not Physics.OverlapSphere)

I would like to check for a collision before an object is instantiated at the start of my game, for procedural level creation 'road' avoidance.

Currently I am using:

       var oHit : RaycastHit;
      var objectPosition = new Vector3(Random.Range(-1.0,1.0) * length, 0, Random.Range(-1.0,1.0) * width);
    var checkResult = Physics.OverlapSphere(objectPosition, 10);
    if (checkResult.Length == 0)     
    {place = Instantiate(object);

but it is not 'accurate' enough, and either avoids the objects entirely, or clips through them. the objects are complex and a simple sphere does not encompass them. I'd prefer a method that would use the mesh to determine collision.

I would like to use:

      var checkResult = object.rigidbody.SweepTest(objectPosition, oHit, 10);
    if (checkResult == false) 
    {place = Instantiate(object);

But it does not work in any way. it may be because I had to make the object a child in order to reset its transform values to zero for instantiation (like 'freeze transformations' in maya); thus it (the parent) has no collider?

for example:

 objectParent(translate 0,0,0)

       |-object  (translate 3892,2873,972)

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

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by PedramAUS · May 29, 2012 at 03:37 AM

You can instantiate the object in an invisible layer and check for the collision if there is no collision change the layer on the fly and make it visible, otherwise destroy it.

http://unity3d.com/support/documentation/Components/Layers

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 Berenger · May 29, 2012 at 03:42 AM 1
Share

You'd need to wait one or several fixed update though, for the collision to be detected.

avatar image SGPascoe · May 29, 2012 at 04:19 AM 0
Share

Right now I'm kind of doing this, that's not the problem. It's the actual way you check the collision that I need.

I'm making another, first layer with the first set of larger objects on, (pretty much the mask of the level, where I don't want things to spawn)

Then the second layer of objects I have shown above, comes in. is SUPPOSED to spawn anywhere but where the first 'masking' layer is.

Then I delete the 'masking' layer's objects.

However using the Physics.OverlapSphere method, it's too inaccurate for the meshes and I end up with it either too far away, or intersecting the mask.

What other method do I use to DETECT the collisions?

avatar image
0

Answer by BSDGuyShawn · Oct 08, 2014 at 01:03 AM

I realize this is an old one, but I use a prefab that is essentially an empty gameobject with a sphere collider and script attached. I instantiate this prefab at the location I want to check. The script has uses Physics.OverlapSphere() in the void Awak() function. It seems to work ok.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Checking Instantiate/Destroy has been called | Checking number of scene GameObjects 1 Answer

How can I check if an instantiated object collides with another instantiated object? 1 Answer

Set parent of instantiated object. 0 Answers

Check if collider is colliding with anything non specific? 1 Answer

Instatiate object after collision detect 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