Some collisions in 2D are not detected, how can I get them all detected?

Hi, I am making a game and I have a lot of it done. When I shoot and hit an enemy they die, but some hits are not detected so the enemy remains alive. Assume the health is 30.

In update I have

if (Enemy_Health <= 0)
 Destroy(gameObject);

in void OnCollisionEnter2D(Collision2D coll)I have

if (coll.gameObject.tag == "Bomb") 
    Enemy_Health = Enemy_Health - 30;
	
if (coll.gameObject.tag == "Bullet")
    Enemy_Health = Enemy_Health - 30;

The bullet has a rigidbody and a box collider. While the enemies have polygon colliders(I have also tested box colliders, but not rigidbody as I have an invisible wall to prevent the player from leaving, which prevents the enemies from entering from off screen).

The code works fine but some of the collisions are not detected and thus an enemy that would die in one hit sometimes dies in 3-5hits. Could someone please help me find a solution or find any mistake in this code. Thanks.

Also in case it helps these enemies are being instantiated from another location/script(moving left) and are being destroyed if they exit the screen left. This is also being done for backgrounds(clouds, ground etc).

I also think coll.gameObject.tag == “Bomb/Bullet” might be the problem as maybe the tag is sometimes not read properly.

I think the reason this is happening is because collision is being calculated every frame. If you are shooting physical objects, and they go fast enough, between the current frame and the next frame, it could travel past the collision all together.

Basically, you’re bullets are shooting so fast that on this frame, it is about to hit the collision and in the next frame it is well past the collision so there was never any time when they actually touched each other.

Instead of using physics to control your bullets, you should use a raycast. There’s lots of reasons, but one of the main reasons is that raycast will not ever miss what it touches. The second biggest reason is that instantiating a bunch of little bullets is way more resource intensive than using a ray. You can probably keep your bomb as it is, but I’d suggest changing how your bullets shoot.

EDIT: Just noticed you said 2D so use this instead: Unity - Scripting API: Physics2D.Raycast