- Home /
Question by
danielmetlitski · Jan 04, 2015 at 04:57 PM ·
collisionphysics2dcollider2dignorecollision
Physics2D.IgnoreCollision Not Working
Hey guys, the following script isn't working. When the collider enters the enemy, it doesnt ignore the collision, but collides and bounces off. ALL COLLISIONS WERE IGNORED!!!! and Enemy was hit are logged and shown when the collision happens, but they bounce off anyway. Can someone please help? Thanks in advance! This is a 2D game.
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("Player"))
{
Debug.Log("player is dead");
}
else if (collision.gameObject.CompareTag("Prison"))
{
}
else if (collision.gameObject.CompareTag("Enemy"))
{
Physics2D.IgnoreCollision(collision.collider, gameObject.collider2D);
if (Physics2D.GetIgnoreCollision(collision.collider, gameObject.collider2D))
{
Debug.Log("ALL COLLISIONS WERE IGNORED!!!!");
}
Debug.Log("Enemy was hit");
}
else
{
Destroy(this.gameObject);
}
}
Comment
Debug displays ALL COLLISIONS WERE IGNORED!!!!, which Debug.Log writes if they were ignored, but they infarct were not ignored, the two objects collide and one bounces off the other. You can see that in my script on line 16.