|
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!
(comments are locked)
|
|
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. :) 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.
Apr 25 '11 at 03:51 PM
microp
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.
Apr 25 '11 at 04:08 PM
Joshua
So, with the raycasting method, you don't need a collider on the source object right? Same with spherecasts and the like?
Apr 25 '11 at 10:45 PM
microp
You do. That's what the ray intersects with and stores in it's raycastHit variable.
Apr 25 '11 at 11:14 PM
Joshua
I mean, on the projectile itself?
Apr 27 '11 at 03:32 AM
microp
(comments are locked)
|
|
You can use GetComponentsInChildren to find the nested colliders:
(Assuming other is your planet collider) Sure, but that doesn't tell me exactly which children's collider actually got hit, does it?
Apr 25 '11 at 03:47 PM
microp
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.
Apr 25 '11 at 11:53 PM
Joshua
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.
Apr 27 '11 at 03:34 AM
microp
(comments are locked)
|
