To kill an enemy I have to hit the very middle of the top for it to register. How do I have a larger contact point?

Viewed 50

If I hit the collider anywhere but exactly in the top center I die. I would like to have it where I could hit off center and I would still kill the gameObject.

 private void OnCollisionEnter2D(Collision2D other)
 {


     if (other.gameObject.CompareTag("Player"))
     {
         Vector2 direction = other.GetContact(0).normal;
         if (direction.y == -1 || direction.y == 1)
         {
             
             player.EnemyKill();
             //GetComponent<Collider2D>().enabled = false;
             Score.Instance.AddHundoPeice();
             Destroy(this.gameObject, 0.1f);

         }
         else
         {   
             other.gameObject.transform.position = sp.lastCheckPointPos;
             checkpoint.dead = true;
             if(other.gameObject.CompareTag("Player"))
                 Lives.Instance.MinusLife();
         }
     }
 }
0 Answers
Related