Child gameObject with collider not colliding if parent has rigidBody

1.- I have a “Player” gameobject with a rigidBody with isKinematic=false (for enemies’ weapons to detect collisions when hitting it) and a CapsuleCollider. The player has a child gameObject “weapon” that has a BoxCollider and a script attached to it that detects collisions with the OnCollisionEnter(), when hitting an “enemy” rigidBody.

2.- I have an “Enemy” gameObject with a rigidBody (isKinematic=false) and a CapsuleCollider attached.

Whenever the player’s weapon hits the enemy, the OnCollisionEnter() of the player’s weapon is NOT called. Only when I remove the player’s parent rigidbody, the OnCollisionEnter() of the child weapon suddenly starts to be called.

Is the “player” rigidBody interfering with its child weapon collisions? Why??

2 Answers

2

this behavior is by design. a rigidbody combines all it’s child colliders to a form a compound collider.
adding another rigidbody as kinematic to your weapon breaks this up again.

Have you found any? I also don't like an enormous amount of entities to recalculate a path every second...

Thanks @hexagonius, I’ll try your suggestion about adding another rigidbody as kinematic to the weapon.

Now, I still don’t understand the reasoning behind the parent’s rigidBody affecting the child’s collisions. Why does it do that? What does it have to do?
If the weapon has a collider, and the object being hit (in this case the enemy) has a collider and a rigidbody, why isn’t the collision being detected?

UPDATE: adding rigidbody as kinematic didn’t work.
What did work was adding a rigidBody (non-kinematic and freezing all rotations and axes) on both weapons (player’s and enemy’s). I recall that solution causing issues in the past… but now, so far, it has worked as expected.

this manual page explains it. go to collision where the weapon is shown: https://docs.unity3d.com/Manual/class-Rigidbody.html