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 lam meng chun · Jul 21, 2011 at 05:09 PM · colliderchildcollisiondetection

detect which child Colliders is touched by other object.

I have a gameObject which have several child and each child have it own collider. How i can know which child collider is touched by other gameObject?

I have get an bad infor from searching in google, all the child collider will belong to parent, it will only return parent name.

Is there have anyway to get the child name when the child collider is touched?

thanks you in advice.

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
0

Answer by Chris D · Jul 21, 2011 at 06:14 PM

Using OnCollisionEnter should get you the name of the collider currently being hit. For example, attaching the following to each of the children you want to monitor:

 function OnCollisionEnter(){
     print(gameObject + " has been hit");

should print the name of the child it's attached to to the console.

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 lam meng chun · Jul 22, 2011 at 03:05 AM 0
Share

oh no! i have 60++ children. This is the only way i can try?

avatar image GregoryFenn · Aug 27, 2019 at 09:00 AM 0
Share

No, this doesn't work because only the top-level parent will have a rigidbody, and so only that parent will get OnCollisionEnter messages (from it's own colliders or it's children's colliders). It would report the same gameObject regardless of which child was hit.

avatar image
0

Answer by GregoryFenn · Aug 27, 2019 at 09:19 AM

I was searching for ages for a solution and this is it. For anyone interested, here is a sample message for OnCollisionEnter which helps explain the process.

 void OnCollisionEnter(Collision collision)
     {
         //My character is a parent player with two children, each of the children 
         //has a collider on. One child is tagged "Player_Head", the other is 
         //tagged "Player_Jacket" (you could also use cp.thisCollider.gameObject.name).
         //As far as I know, collision.contacts is the only place where "thisCollider" 
         //can be found.
         ContactPoint cp = collision.contacts[0];
         if (cp.thisCollider.gameObject.tag == "Player_Jacket")
         {
             print("Jacket hit");
         }
 
     }


[Solution derived from @SpaceManDan's observation in a comment here: https://answers.unity.com/questions/762004/how-do-you-detect-which-child-collider-was-hit.html ]

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Unity creating static colliders 1 Answer

How do i get world position of collider if it inside multiple scaled gameobjects? 0 Answers

How to detect child object collisions on parent 3 Answers

Collider enabled when child object is destroyed 0 Answers

Collider Bug 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