Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 microp · Apr 25, 2011 at 04:38 AM · collisioncolliderchildoncollisionenterhierarchy

Getting a collision's bottom-most collider in a hierarchy

Hi!

I've got a projectile colliding with a planet to which various buildings are attached as childs. All have colliders. I'd like to know when a building is hit, but OnCollisionEnter's Collision.collider only gives the topmost GameObject, the planet.

I just read that I could look at the contacts list, but is this really the only way? Isn't there a way to get "collider" to just give the bottommost object directly?

I also know about the raycasting option, but that sounds like an irritating and costly workaround to me.

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

2 Replies

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

Answer by Joshua · Apr 25, 2011 at 04:42 AM

Actually, I think raycasting is the easiest way. It seems complicated when you've never used it, but read up on it here and try it. :)

Comment
Add comment · Show 7 · 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 microp · Apr 25, 2011 at 03:51 PM 0
Share

You know, you're right, it doesn't look that complicated. I'm only annoyed at all the little things that Unity's physics got wrong. Thanks, I'll look into it. I'll still wait a bit for other potential answers to show up though.

avatar image Joshua · Apr 25, 2011 at 04:08 PM 0
Share

I used to feel exactly the same. But now that I feel I understand more of it it's rather that the physics is enormously powerful, but has to be used correctly. And it's designed for non-stressed situations because it's made to run in the background of every project - so it's not perfect in every situations, it's made to always be 'good' and not recourse intensive.

avatar image microp · Apr 25, 2011 at 10:45 PM 0
Share

So, with the raycasting method, you don't need a collider on the source object right? Same with spherecasts and the like?

avatar image Joshua · Apr 25, 2011 at 11:14 PM 0
Share

You do. That's what the ray intersects with and stores in it's raycastHit variable.

avatar image microp · Apr 27, 2011 at 03:32 AM 0
Share

I mean, on the projectile itself?

Show more comments
avatar image
0

Answer by Casper 1 · Apr 25, 2011 at 10:26 AM

You can use GetComponentsInChildren to find the nested colliders:

Collider[] childrenColliders = other.GetComponentsInChildren<Collider>();

(Assuming other is your planet collider)

Comment
Add comment · Show 3 · 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 microp · Apr 25, 2011 at 03:47 PM 0
Share

Sure, but that doesn't tell me exactly which children's collider actually got hit, does it?

avatar image Joshua · Apr 25, 2011 at 11:53 PM 0
Share

I'm just guessing here, but couldn't you cross reference this with the contacts list and then take the entry of your childrenColliders array with the highest index? This will be the bottommost collider since they're added by parent/child and alhabetical order.

avatar image microp · Apr 27, 2011 at 03:34 AM 0
Share

Well in the case of my projectile, it hits only one target at any one time, so the contacts list always contains the exact object that got hit. That works. But Collision.collider is still utterly useless.

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

No one has followed this question yet.

Related Questions

Weird Collision Detection with a Cube and OnCollisionEnter 2 Answers

Collider isn't working ? 2 Answers

Detect collision point?? 1 Answer

OnCollisionEnter of Projectile detects parent with rigidbody instead of child objects with collider 2 Answers

Check if collider is colliding with anything non specific? 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