Detecting collision doesn't work

I am making an FPS game and the bullets from the enemy go through walls and I tried to make the bullets destroy when they collide a wall and they don’t do anything.


Here is the code and I have set the tags correctly.

Well, first I would add a Debug.Log to the OnCollisionEnter to see if it’s trigger.
Next, you mention walls, but your Tag check is for Ground. Is this what you expect?
Then, if it’s not triggering, you should check to the OnCollisionEnter docs

to make sure you have things setup correctly. This tells you what is required for collisions to register.

1 Like

I added a Debug.Log but nothing happened, then, the wall’s tag is Ground because I made it with ProBuilder so I put Ground to make it jumpable and it has the same tag in the inspector and in the script. Then, I didn’t understood the collision docs, what do I need to make it work? I’m new to Unity

1 Like

You can call
Destroy(gameObject, 2);
in Start, if you know you want to destroy it in 2 seconds. No need to use a timer unless the duration could change per bullet.

For collisions, check the docs and be sure there are the right components on the wall and bullet. Also try a slow bullet in case it’s going through the wall, if they are fast enough the physics engine can’t catch the collision.

Notes: Collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached…

lol mmmm i’m not going to remove a given like but … it was for Brathnann’s answer

1 Like

Try to make OnTriggerEnter instead of OnCollisionEnter.

That was it, I forgot to attach a rigidbody to the bullet, now works

Ok, I’ve ran into another issue, now the bullet acts with gravity even when I disable it, Any idea on how to fix it?

Just tick IsKinematic.

When I tick IsKinematic the bullet doesn’t destroy when it goes through a wall

You shouldn’t use isKinematic for your case. I don’t know why gravity is affecting your bullet, it shouldn’t be. Be sure everything is set up correctly. And do more tutorials and research to get a feel for how things go together.