- Home /
Is this a correct way to have multiple different compound colliders in one gameobject?
Hi,
I'm currently trying to make a gameobject that has multiple colliders and I want different action to be performed depending on which collider was triggered. However, due to compound collider listening to every collider in children, I was having difficulty making it work as I wanted. So I came up with this solution and I was wondering if this is proper way to do this. Basically, I gave rigid bodies to the child object as well as the root parent object and then connected the child rigid bodies to parent using fixed joint. Each child object will have their own children with colliders attached to it resulting in multiple different compound colliders in one gameobject.
Would this setup work as I'm hoping or will there be any negative consequence that I am missing? I've made mass of parent very high and mass of child rigid bodies low so the movement happening on parent object won't be affected by child's physics. My main worry is having multiple rigid bodies on same gameobject as I heard it can sometimes cause physics to behave unpredictably.
Answer by CraigGraff · Jul 02, 2017 at 08:54 PM
If you can switch to OnTriggerEnter you could just make your child colliders have kinematic rigidbodies. You will get the events and you don't have to worry about hooking everything up with fixed joints or having your colliders get knocked out of joint.
What kind of objects are expected to be colliding with the child objects? Is this for combat, movement, both? Something else?
Depending on your use case it might actually be more straightforward to have the collision script and the rigidbody on the other objects (those not part of the hierarchy you mentioned). That way you know exactly which objects are hit. You could then use SendMessageUpwards to send the event to the parent object (or if performance is a special concern using a standard C# event or a UnityEvent might be an option).
I'm planning on this object being a projectile. The reason I wanted separate collision was so I can have one set of colliders as hitbox and other set of colliders as potentially other effect a projectile may have such as ho$$anonymous$$g on nearby enemies that enters the larger collider range and the reason why I wanted parent child relationship is so that I can just move the parent using parent's rigid body and make all colliders follow it.
I just tested kinematic rigid body and it seems to be behaving as I wanted. Thank you!