- Home /
Question by
pro_bro316 · Mar 30, 2019 at 10:36 AM ·
collisionunity 2dphysics2dcollider2d
Ignore collision at the start of the game.
I am trying to create a neuroevolution AI for flappy bird. The problem is when i create a population for 50 birds. They collide with each other at the start of the game. However i have ignored the collision through the following code but it's not working at the start.
private void OnCollisionEnter2D(Collision2D collision2D) {
if (collision2D.gameObject.tag == "ignore")
{
Physics2D.IgnoreCollision(collision2D.collider, gameObject.GetComponent<Collider2D>());
return;
}
else
{
isDead = true;
anim.SetTrigger("Die");
Destroy(gameObject);
}
}
capture2.png
(131.6 kB)
Comment
Answer by pro_bro316 · Mar 30, 2019 at 10:55 AM
Just found out the answer for it myself. I just replaced the collisionenter2d with triggerEnter2D. I guess trigger function is called before start.