- Home /
2D Colliders Not Working
Hello, I'm pretty sure I've done everything right to make my objects collide but they dont! My Project is a 2d project and has 2d mode on My games is where i have the player in the middle of the screen and enemies come at him. I have a shield thats moves when you touch a side of the screen. I want it so the enemies collide with the shield and explode (destroy).The enemies are instantiated so i added this script onto the enemy:
void OnCollisionEnter2D (Collision2D col)
{
//Check collision name
Debug.Log("collision name = " + col.gameObject.name);
if(col.gameObject.name == "Shield")
{
Destroy(this.gameObject);
}
}
}
And i put 2d ridgidbody's and 2d box colliders on the enemies and the shield. The ridgidbody's are not kinematic, the gravity is just turned off. If this is just a bug in Unity then should I restart the project? Any help is greatly appreciated! Thanks!
no, thats why I'm confused because if I did get the debug.log then it would've just been a scripting error
that means they are not colliding. so OnCollisionEnter2D is not getting called.
ok, how do I make it so they collide because right now they just pass through each other?
Try to use on ColliionStay2D just to check. does it collide or not, it more sensitive then OnCollisionEnter
Answer by Chrisasan · Aug 17, 2015 at 12:28 PM
IF they are passing through each other, then you need to toggle the IsTrigger flag on the collider to false, not checked. If Is Trigger is checked then you need to use OnTriggerEnter2D() rather than OnCollisonEnter2D()