Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Two EdgeColliders2Ds don't trigger collision / don't collide

Discussion in 'Physics' started by svope, Feb 2, 2015.

  1. svope

    svope

    Joined:
    Jul 6, 2014
    Posts:
    8
    Hi guys,

    I'having a problem which I cannot solve, I posted this to Unity answers and moderator rejected that post.

    Problem:
    collision.jpg

    On the picture you can see GREEN road and WHITE ball. Both have edge collider2D component which you can see as those very thin green lines. WHITE ball has a rigidbody2D component ( not Kinematic ) and edge collider2D set as trigger.

    The problem is, those two edge colliders2D don't collide -> there is no OnTriggerEnter2D() or OnCollisionEnter2D() (if I set ball's edge collider as non trigger ) call.

    If I change ONE of those two edge colliders2D to any other 2D collider ( box, circle..) everything works well...

    The code is just standard..
    Code (CSharp):
    1. // this belongs to script attached to the WHITE ball GameObject
    2. // which has EdgeCOllider2D set as Trigger
    3. void OnTriggerEnter2D(Collider2D col)
    4.     {
    5.         Debug.Log( "segsegsege" );
    6.         if ( active_road != col.gameObject )
    7.             col_go.Add(col.gameObject);
    8.     }
    So why two edgeColliders2D don't collide and any other "combination" like edge + box, edge + circle, box + box etc.. works?
     
  2. Uberpete

    Uberpete

    Joined:
    Jan 16, 2014
    Posts:
    78
    Maybe you'd like to look at the documentation: http://docs.unity3d.com/Manual/class-EdgeCollider2D.html

    EdgeColliders are usually used on straight edges, not round stuff like balls. It isn't an "edge" collider per-se but more of a simple surface collider. In the screenshot you posted, the lines are the colliders: the ball's collider isn't in the ball, its just sticking out randomly.

    Unless you really have to, I'd use a polygon/circle collider. Otherwise modify the vertices of the edge colliders.
     
  3. svope

    svope

    Joined:
    Jul 6, 2014
    Posts:
    8
    Uberpete, thank you, BUT THAT IS NOT THE PROBLEM

    Two objects, both have edge colliders, OnTriggerEnter2D() is NOT called
    noCOL.jpg

    THE SAME two objects, where one of them has box collider2D instead of edge collider2D
    and then the OnTriggerEnter2D() is CALLED
    yesCOL.jpg

    I dont care about shapes etc, just why two objects with edgeColliders2D dont call OnTriggerEnter2D (or other collision functions doesnt really matter...).

    For me, it seems like a Unity bug, because as I said, any other combinations of colliders2D WORKS, but ONLY when there two edgeColliders2D then it does NOT work.

    These pictures are from totally new projects, just 2 GameObjects with colliders, one of them with rigidbody and script:
    Code (CSharp):
    1. public class test : MonoBehaviour {
    2.  
    3.     // Use this for initialization
    4.     void Start () {
    5.  
    6.     }
    7.  
    8.     // Update is called once per frame
    9.     void Update () {
    10.  
    11.     }
    12.  
    13.     void OnTriggerEnter2D()
    14.     {
    15.         Debug.Log("TRIGGER");
    16.     }
    17. }
     
  4. Uberpete

    Uberpete

    Joined:
    Jan 16, 2014
    Posts:
    78
    That's because you're calling OnCollisionEnter2D, not OnTriggerEnter2D. Try this:

    Code (CSharp):
    1. void OnCollisionEnter2D (Collision2D col){
    2.  
    3.      Debug.Log ("Hola " + col.gameObject.name);
    4.  
    5. }
     
  5. svope

    svope

    Joined:
    Jul 6, 2014
    Posts:
    8
    I copied a bad piece of code,sorry, but I tried it anyway (written in first post).
    The thing is it just doesn't work.
    You can try yourself if you want ( attachment )
     

    Attached Files:

  6. Uberpete

    Uberpete

    Joined:
    Jan 16, 2014
    Posts:
    78
    I had a look at Box2D manual (Unity's 2D physics engine).

    Its not possible.
     
    Estecka likes this.
  7. svope

    svope

    Joined:
    Jul 6, 2014
    Posts:
    8
    Thank you! Didn't know about this :)