• 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
2
Question by dkoontz · Jan 27, 2010 at 10:41 AM · collisionphysics

What might cause Physics.IgnoreCollision to not function?

I'm trying to do a very basic thing, have my turret not collide with the missiles it's launching. Missile is a prefab reference.

GameObject missile = (GameObject)Instantiate(Missile, centerTube.position, centerTube.rotation);
BoxCollider turretCollider = transform.Find("Ball").GetComponent<BoxCollider>();
Physics.IgnoreCollision(turretCollider, missile.collider);

The "Ball" child object is what the collider that's causing problems is actually attached to. There is another collider on the main GameObject but it's a trigger and used for activating the firing of the turret. Could having two colliders on different parts of a prefab hierarchy be causing issues? I've tried everything I can think of, even adding this to my Missile's behavior.

public void OnCollisionEnter(Collision other) {
    if(null != other.collider) {
        Physics.IgnoreCollision(collider, other.collider);
    }
}

But the instantiated missile is still effected by the box collider. Of course, turning that collider into a trigger makes everything work fine, no more collisions, but then that breaks everything else. Any ideas?

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

1 Reply

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

Answer by duck · Jan 27, 2010 at 11:31 AM

The problem may be that if any objects have 'rigidbody' components, a rigidbody will use all the colliders (excep mesh colliders) on any of its child objects together as a single "compond collider". That is, unless the child object also has a rigidbody component, in which case the rigidbodies act as independently moving objects even though they have a parent-child relationship in the hierarchy.

So it could be that wherever your rigidbody component is (if you have one), it's greedily assuming that all child colliders should belong to it, and that may be causing confusion about which colliders should be ignored - or something like that!

Perhaps you could solve your problem by restructuring your hierarchy so that there's a separate gameobject with the trigger collider used for activating the firing, and make that entirely separate from the turret itself in the hierarchy.

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 dkoontz · Jan 27, 2010 at 07:28 PM 0
Share

Interesting, I didn't know a compound collider grabbed all the child colliders, good to know! Unfortunately there's no rigidbody on any part of my turret.

I will try the separate GameObject with the non-trigger collider to see if I can get IgnoreColliders to function with that configuration.

avatar image dkoontz · Jan 31, 2010 at 09:32 AM 1
Share

Setting the child objects to have mesh colliders did resolve my problem.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How to use Physics.IgnoreCollision for multiple objects / toggling collisions for multiple, specific objects? 0 Answers

Having more than one collider in a GameObject? 8 Answers

Changing mesh collider's mesh cause objects go into mesh. 1 Answer

Rigidbody necessary to use collision detection 1 Answer

How can I make two Character Controllers Collide 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