• 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 Will M · Nov 06, 2012 at 12:53 AM · colliderparentchild

Collision detection on all children of empty parent

I have a spaceship that is a sum of components, such as hull, engine, guns, etc. These are all children of an empty PlayerShip object. How do I detect collision on the player's ship all at once, without handling collision for each ship component?

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
1
Best Answer

Answer by Kryptos · Nov 06, 2012 at 02:29 PM

Add a rigidbody component to the parent (PlayerShip) GameObject. All collision will then be caught by this object. This is what UT call compound colider.

See Rigidbody (documentation)

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 Will M · Nov 06, 2012 at 06:58 PM 0
Share

Thanks, thats what I was missing, I didn't realize i needed a rigidbody on the empty object.

avatar image Will M · Nov 06, 2012 at 07:42 PM 0
Share

I'm still having trouble getting the compound collider to work. http://imgur.com/a/Tddso#0 is an album of what my setup looks like. It might be poorly set up and that is causing problems, I dunno.

avatar image
0

Answer by Owen-Reynolds · Nov 06, 2012 at 01:07 AM

Just check for collision the usual way (script on the parent.) All the child colliders count as one big collider on the parent.

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 Will M · Nov 06, 2012 at 06:33 AM 0
Share

I'm trying to do this code Physics.IgnoreCollision(clone.collider, transform.root.collider); where clone is the laser and transform.root is the empty playership object, but I get this error:

$$anonymous$$issingComponentException: There is no 'Collider' attached to the "PlayerShip" game object, but a script is trying to access it. You probably need to add a Collider to the game object "PlayerShip". Or your script needs to check if the component is attached before using it.

avatar image Kryptos · Nov 06, 2012 at 07:52 PM 0
Share

You should not use IgnoreCollision but set the collision layers properly so that your bullet does not interact with your gun.

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

12 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

Related Questions

Make a simple tree 1 Answer

How can I access a Collider's GameObject in script? 1 Answer

Ignoring the raycast of a child collider but not parent. 2 Answers

OnTriggerEnter - check if collider is child 1 Answer

How to detect child object collisions on parent 3 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