Hit Detection Issues with multiple colliders on 1 mesh?

I’ve been pushing ahead on my game and ignoring a bug that I was hoping I would figure out if I just thought about it longer. I think I figured out what’s causing the problem now.

I have a shooter game with a fps gun that follows the mouse which is a GUI crosshair The bullets shoot from offscreen to wherever the mouse is pointed. the bullets are unity cubes with rigid bodies and box colliders on them.

My enemies are skinned soldier models I made. Each enemy has 2 box colliders, 1 is attached to the headbone, the other is attached to the pelvis.

The problem I have is sometimes when I shoot the enemy the hit will not register. The bullet will simply ignore the enemy and hit the “back wall” which is an invisible box collider that resets the bullet’s position on impact ( I reuse the same 10 bullets because the game is for mobile, I reuse the same 6 enemies over and over again too.).

I’ve narrowed down the problem to 1 of 2 things, and I was hoping someone here might have experienced this as well and could tell me for sure what the issue is.

  1. The problem has something to do with two or more box colliders on the enemy mesh which are touching each other, this will cause the bullet collision to not register? So if the head and torso colliders are touching (because the enemy is crouched down and the head is looking down) the bullet wont register as hitting because there’s already a collision happening on the enemy mesh? What I’ve done is reduced the size of the head collider and this seems to have fixed the above (I think).
  2. but if I put the enemy too close to a prop that has a box collider on it the bullet impacts wont register either. So I’ve been moving the enemies far away from the props. and this helps too.
  3. The bullet may be going too fast… When I reduce the speed of the bullets the hit detection issues go away for the most part, but not always.

Using the methods above I have a pretty good success rate now, not 100% because sometimes an enemy will simply just stay invincible though. I’m thinking its that when two box colliders are hitting each other a third wont register as a hit?

The box colliders on the enemy mesh both have scripts attached to them with only oncollisionenter functions in them, they check to make sure the colliding object is tagged with bullet and fire off hit(); / death(); functions in a script attached to the main enemy mesh.

This sounds like your problem:

The bullet may be going too fast… When I reduce the speed of the bullets the hit detection issues go away for the most part, but not always.

There’s a script on the wiki which will sort it out for you: DontGoThroughThings