Why do my collision not work???

HI!

I am having some trouble with 2Dcollision. I have a player and a moving obstacle. They both have an edge collider, and my obstacle has a ridgibody too (all 2D versions).

I am trying to destroy the obsticle and reduce lives total by one every time i colide with an enemy.

this is the code i am using on my player:

void OnCollisionEnter2D(Collision2D col)
    {
        Destroy(col.gameObject);
        lives -= 1;
    }

When the player and obstacle should colide they just pass by each other instead… i have no clue why… i hope someone can help :smiley:

Your codes look fine.You should check if trigger checkbox checked in the inspector for your collider and if it doesnt change you should change edge collider if my memory serves well i had alot of issues with edge collider once.

You know the edge collider is a line maybe you should change it. A box collider perhaps and edit it’s size. Maybe put a tag on the objects too.

You can add a backup by also adding

     void OnCollisionStay2D(Collision2D col)
         {
             Destroy(col.gameObject);
             lives -= 1;
         }

Just in case the OnCollisionEnter2D, for whatever reason doesn’t register, like fast moving objects. For very fast moving object, it may help to use a RayCast2D to detect Collisions.