- Home /
Collider wont collide. But I have done everything correctly.
So I'm pretty sure there is 0 reason for this to be happening but I'm making a top-down shooter and I have an enemy which has a box collider 2D attached to it and I have a projectile that has a circle collider 2D and a Kinematic Rigidbody attached to it. I have tried to add a mesh collider but that didn't seem to do much. I'm using the OnTriggerEnter2D function with the colliders set to 'Is Trigger' but the projectile just passes through the enemy and doesn't do anything at all. I have done everything correctly that I'm aware of but it just won't work. This code below is attached to my Enemy and it should destroy the enemy apon contact with the projectile but it dosnt :(.
private void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Projectile"))
{
Destroy(gameObject);
Destroy(other.gameObject);
}
}
How do you move your objects? Depending on what you do here there will be no collision detection.
Answer by JDelekto · Jun 08, 2019 at 10:59 AM
I would add a Debug.Log() in your OnTriggerEnter2D() to see if you are even getting in there and if you are, then log the tag of the object as well.
Make sure that the name of your tag and the tag "Projectile" are the same case. (i.e. upper-case 'P', the rest of the letters lower-case.
Aside from that, and it is not obvious from the code snippet itself, is to look at the layers that your objects are on and look at the physics layer interactions (Edit > Project Settings > Phyiscs 2D) to see if the interaction between them is un-checked.
Also flip the two destroy statements because you don't want to destroy the enemy before you destroy the projectile. Otherwise you will most likely get an error (or nothing will happen to the projectile) since the enemy is destroyed before the code runs.
So I did all of this but in the end, it ended up being I had to put this part of the script onto the projectile script, changing the projectile tag and then it worked. Thanks for your help anyway, glad to finally get it working. :)
Your answer
![](https://koobas.hobune.stream/wayback/20220612202823im_/https://answers.unity.com/themes/thub/images/avi.jpg)