- Home /
Way to Make Multiple Colliders act like Single Collider
There are several enemies in the game I'm making with fairly complicated geometry. Since I'm using mesh colliders (made using meshes imported from Blender), I've had to make them convex for rigidbodies to handle them - which means that I've had to add a bunch of collider-meshes as children of each enemy in order to handle their collision geometry.
This has worked fine for rigidbody work - but it runs in to problems when I start throwing around AoE attacks. A hit to any of the colliders has to register damage, so all of them will register an attack and pass the damage dealt to the central damage-handling script. However, this means that if the AoE (using a SphereCast) hits multiple colliders, all of them register damage. This is a problem, since I want the enemy to only take damage once.
It seems like a solution to my problem would be either to find a way to get all these colliders to behave like they're the same collider, or to find a way to make a complex mesh collider that can have concave geometry while still working with rigidbodies. Any help on either of these routes would be appreciated.
Ins$$anonymous$$d of having your "AOE" "attacks" doing a SphereCast
, you could just check yourself for distances to the objects. It might not be as accurate, but it is certainly just as useful and a lot faster.
Answer by nesis · Jan 22, 2014 at 05:22 AM
You need to be more robust in your handling of damage registration. If damaged, record that somehow (eg add the damager to a list of objects that have damaged the character during this frame) in the central damage-handling script, and just reset that record at the start of each frame.
To ensure the record gets reset before trying to do damage in the next frame, you'll need to set your central damage-handling script to be earlier in execution order than the child rigidbody's script, and perform the reset at the start of Update() (or whatever update method you're using).
So, since it seems there's no simple way to make a concave mesh collider, that leaves me needing a way to separately identify each damage source so as to count it exactly once.
With that in $$anonymous$$d, does Unity let you retrieve something like a hash code for each object? I'd need something like that to make my damage handling more robust, since I'd have to be able to distinguish between two different objects named "ElectroBlast (clone)".
Why not just compare references. It's much cheaper than hashing the object, then comparing that. References are always very cheap.
So how do you compare references? I'm not familiar with the term as you're using it. Thanks!
Lets say you have 2 objects, object 1 and object 2, and at a certain point you reference object 2 somewhere in object 1. At a later point object 1 encounters another object unknown to it. To find out whether that unknown object is in fact object 2, you can compare the reference to the unknown object to that of object 2.
If you don't know what references are and how they are used/created/compared, then you should read up on basic OO.
Physics.SpherecastAll will return a list of colliders. You can iterate over that list, and check if the same collider is in it twice by comparing two colliders with ==, just like you would for ints, strings, etc.
Your answer
![](https://koobas.hobune.stream/wayback/20220613131105im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unity2D side collision detection 1 Answer
Object Collision PLEASE HELP!!! 1 Answer
Player shaking when colliding with objects 3 Answers