Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

CircleCollider2D not colliding with BoxCollider2D?

Discussion in '2D' started by Sickwitit, Mar 9, 2015.

  1. Sickwitit

    Sickwitit

    Joined:
    Dec 22, 2014
    Posts:
    123
    void OnCollisionEnter2D(Collider2D collision)
    {
    if (collision.gameObject.tag == "Platform")
    Debug.Log("Collision");
    }

    They are colliding, but this debug message isn't showing. Both of these objects are rigidbody2D's. One has a CircleCollider2D , and one has a BoxCollider2D. Why would this collision not work? Any help would be appreciated. Triggers work, but am not trying to use triggers in this situation.
     
  2. PGJ

    PGJ

    Joined:
    Jan 21, 2014
    Posts:
    897
    Have you checked what the tag contains on collision?
    Code (CSharp):
    1. void OnCollisionEnter2D(Collider2D collision)
    2. {
    3. Debug.Log("Tag: " + collision.gameObject.tag);
    4. if (collision.gameObject.tag == "Platform")
    5. Debug.Log("Collision");
    6. }
     
  3. Xelnath

    Xelnath

    Joined:
    Jan 31, 2015
    Posts:
    399
    Check project settings to see which layers can collide with each other:

    Edit -> Project Settings -> Collision 2d
     
  4. Illia_Komendantov

    Illia_Komendantov

    Unity Technologies

    Joined:
    Jan 27, 2015
    Posts:
    5
    You should use correct parameter type for OnCollisionEnter2D, it is "Collision2D" and not "Collider2D".
    Correct code will look as:
    void OnCollisionEnter2D(Collision2D collision)
    {
    if (collision.gameObject.tag == "Platform")
    Debug.Log("Collision");
    }
     
    Sickwitit likes this.
  5. Sickwitit

    Sickwitit

    Joined:
    Dec 22, 2014
    Posts:
    123
    First of all, you were right, thank you! On the other hand, I found that one of my Debug.log's was in one of my update methods, so even if it were coded correctly, this Debug.log in the update method was constantly getting called, while not being able to see "per event/collision" Debug.log's!
     
  6. Sickwitit

    Sickwitit

    Joined:
    Dec 22, 2014
    Posts:
    123
    Yes, I did check and it is the correct tag, it looks like it was "Collision2D" as the parameter and not "Collider2D".
     
  7. Sickwitit

    Sickwitit

    Joined:
    Dec 22, 2014
    Posts:
    123
    Good advice, but this wasn't the issue. Thanks.