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 MNNoxMortem · Sep 27, 2017 at 08:59 PM · collisionphysicscolliderhealth

How to properly use Physics.Checkbox to ensure an object can be instantiated at a specific location without collision

Physics.Checkbox does not work at all as I would expect it. Therefore I would be glad for any help helping me to find where my usage of it is erronous. I have used GameObject.CreatePrimitive(PrimitiveType.Cube) to create cubes at the very position Physics.CheckBox should test for collision and there is simply no object. Especially since I run these from UnityTest (PlaymodeTest) to ensure that the given object is placeable and that no other invisible collider exists in the scene..

         var obj = /* GameObject with a BoxCollider 0.1,0.4,0.1 standing on- the floor. I have verified this */
         var c = /* The BoxCollider of obj */
         
         var instance = Object.Instantiate(obj);//Instantiates at 0,0,0 by default. The gameobject.transform is 0,0,0
         instance.SetActive(false);//Set the gameobject inactive to disable collisions with instance

         var position = Vector3.zero /* some position to test for collision. */
         var p = position + c.transform.localPosition + c.center; // The position where the BoxCollider would be IF the object was placed at position.
         Assert.IsFalse(Physics.CheckBox(p,//center of the would-be position of the collider
                                  c.size / 2F,//equals c.extents
                                  c.transform.rotation),"There should be no collision");//CHECK

         instance.transform.position = Vector3.zero;
         instance.SetActive(true);

         //Instance now sits at 0,0,0 with a collider of 0.1, 0.4 , 0.1 such that 0,0,0 is the center bottom of the BoxCollider
         Assert.IsTrue(Physics.CheckBox(p,//center of the would-be position of the collider
                                  c.size / 2F,//equals c.extents
                                  c.transform.rotation),"There should be collision");//ASSERT FAILED - there was no collision, but we expected collision


Maybe my math is simply wrong, but I am pretty sure it isn't as I have created cubes exactly at the position and size I use for CheckBox and they are exactly as I expect them to be. Maybe it has to do with testing collision during the same frame or that SetActive(false/true) does not disable/enable the collisions for Physics.CheckBox.

I really do not see what could be wrong anymore, any help or guidance therefore is highly appreciated.

Thanks!

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

148 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 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

Compound collider object behaving as a whole? 1 Answer

Disable/Enable Colliders 1 Answer

object goes through another object error 1 Answer

Is there anyway to see if another Object has any Collision? 1 Answer

OnCollisionEnter: collision.gameObject has weird behaviour 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