title: Unity - Box Collider not working properly
body: <p><a href="https://i.stack.imgur.com/Jz4do.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Jz4do.png" alt="enter image description here"></a></p>
  
  <p>I have 2 Box Colliders(green boxes) and a ball in my scene. Whenever the ball touches the bigger Box Collider <em>the player dies and the game is over</em>. However, if the ball is on the smaller collider(as it is in the pic), the player is fine and the game continues to run.</p>
  
  <p><strong>PROBLEM</strong></p>
  
  <p>When I drop the ball from a height, sometimes the ball manages to touch the bigger Collider(maybe because of its momentum) and <em>my player dies</em>. As I said this doesn't happen always which is resulting in an unpredictable outcome. </p>
  
  <p><strong>WHAT I DID TO SOLVE THIS PROBLEM</strong></p>
  
  <p>I added <code>rb2d.velocity = Vector2.zero;</code> to stop the ball as soon as it collides with the smaller <code>Collider</code>. But it didn't work.  </p>
  
  <p><em>light</em> is the <code>tag</code> associated with the Game object that has smaller Box Collider attached to it.</p>
  
  <pre><code>private void OnCollisionEnter2D(Collision2D collision)
      {
          if (collision.gameObject.CompareTag("light"))
          {
  
              Debug.Log("collision");
              rb2d.velocity = Vector2.zero;
              return;
          }
          // Zero out the ball's velocity
          rb2d.velocity = Vector2.zero;
  
          Debug.Log("gameovercollision");
          // If the ball collides with something set it to dead...
          isDead = true;
          //...and tell the game control about it.
          GameController.instance.PlayerDied();
     }
  </code></pre>
  
  <p>I even tried releasing the ball from the same height but still, the behavior was unpredictable.</p>
  
  <p><strong>LOGS</strong></p>
  
  <blockquote>
    <p><strong>gameovercollision</strong>
    UnityEngine.Debug:Log(Object)
    Ball:OnCollisionEnter2D(Collision2D) (at Assets/Scripts/Ball.cs:63)</p>
    
    <p><strong>collision</strong><br>
    UnityEngine.Debug:Log(Object)
    Ball:OnCollisionEnter2D(Collision2D) (at Assets/Scripts/Ball.cs:54)</p>
  </blockquote>
  
  <ul>
  <li><p>What's the reason for this behavior?</p></li>
  <li><p>Why does not the smaller  Collider stop the ball perfectly?</p></li>
  <li><p>How can I solve this problem?</p></li>
  </ul>