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 /
  • Help Room /
avatar image
3
Question by bificommander · Apr 28, 2017 at 02:39 PM · collidersparent and childcollider.oncollisionenter

Distinguishing multiple colliders on one object

I'm working on a simple helicopter simulation. I want the helicopter to have different colliders for the rotor and the landing gear, with different behaviors depending on which of the two is having a collision.

Several other answers to similar questions I found suggest adding empty child objects to the parent object adding and the different colliders and scripts to different child object. But when I do that, the OnCollisionStay and similar functions do not trigger in scripts attached to the child objects. Only the functions in the script of the parent object triggers if any of the child colliders hit something. Whether or not the parent object has a collider of its own doesn't seem to matter.

I wouldn't actually mind that all the trigger signals are received by the parent object, as that's where I control the rotation and speed of the helicopter. But I still can't distinguish by which collider triggered the collision event.

Does anyone know either a way for me to distinguish the collision triggers inside the parent object, or to have the collision events fire in the child events that contain the script and collider instead of the parent object?

PS: I haven't set the colliders to IsTrigger=true, because I appreciate not having to make sure myself that a landed helicopter doesn't fall through whatever it landed on. If neccesary I could change that.

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

Answer by bificommander · May 06, 2017 at 07:21 AM

I found this solution

     void OnCollisionEnter(Collision collision)
     {
         foreach(ContactPoint contact in collision.contacts)
         {
             var colName = contact.thisCollider.name;
             switch (colName)
             {
                 case "Rotor":
                     //Do something
                     break;
                 case "LandingGear":
                     //Do  something
                     break;
                 case "Body":
                     //Do something
                     break;
             }
         }
     }
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 QuillsInteractive · Jul 25, 2018 at 09:53 AM 2
Share

but how do you define name for each collider ?

avatar image Baconation QuillsInteractive · Sep 24, 2019 at 08:03 PM 0
Share

I suppose each collider would have to be placed on a separate child gameobject so that you can get the name of the object the collider is on.

avatar image
0

Answer by Szarley-Dwarf · Apr 30, 2017 at 05:10 PM

I found that kind of solution works on some occasion for a colliders on one object.

     if (other.GetType () == typeof(EdgeCollider2D)) {
         //do stuff 
     } else if(other.GetType() == typeof(CircleCollider2D)){
                   // do stuff
     }

it didn't work for me :/ but maybe that will be helpful for you.

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 bificommander · Apr 30, 2017 at 07:19 PM 0
Share

Thanks. I'll give it a shot tomorrow. Question though: Since this code snippet refers to "other", is this code supposed to go into the objects that the helicopter can collide with (i.e. the ground and all buildings)?

avatar image Szarley-Dwarf bificommander · May 01, 2017 at 08:51 AM 0
Share

I'm not sure to be honest. I'm Game Dev & Unity newbie and just start to learn it. I place that code on the player object on which I check the collisions with other world objects. If that was wrong let me know.

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

102 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

Related Questions

Enemy Trigger Colliders are triggering my player's trigger collider. Why? 1 Answer

Player respawn after collision 0 Answers

Untouchable child objects of first person controller 1 Answer

Find a collision point from inside the object. 0 Answers

URGENT!!! Colliders don't respond/move with imported Maya animation? 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