Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

OnTriggerEnter2D triggers before the collision

Discussion in '2D' started by dayone, May 18, 2015.

  1. dayone

    dayone

    Joined:
    Apr 9, 2014
    Posts:
    4
    I have one circle game object with circle collider and one rectangle with box collider. When circle hits to one of the edges of the rectangle, OnTriggerEnter2D triggers. When I zoom in to collision point though they are really close to each other, I can see that both objects are not colliding. You can see this on first screenshot.

    While playing with the editor I observed a strange behavior. From the Hierarchy window I selected the circle gameobject and then while pressing Ctrl I selected the rectangle gameobject. When I did this another collider emerged on top of the circle as can be seen on the second image. As you can see the new emerged polygon collider is colliding with the box. I am guessing this the reason of my problem.

    As I said at the begining I have only circleCollider2D attached to the circle so I dont know what poygon collider is doing there.

    Does any one have any idea how can i fix this issue?

    CircleCollider1.png CircleCollider2.png
     
  2. Aaron_T

    Aaron_T

    Joined:
    Sep 30, 2014
    Posts:
    123
    Does the circle have any child objects that have colliders attached to them?
     
  3. Gardes

    Gardes

    Joined:
    Apr 7, 2015
    Posts:
    46
    dayone and theANMATOR2b like this.
  4. dayone

    dayone

    Joined:
    Apr 9, 2014
    Posts:
    4
    They dont have any child objects attached.
    Both circle and rectangle have Sprite Renderer, 2D Collider and Rigidbody2D attached with no child or parent.
     
  5. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
    At least those blue lines are from sprite mesh, not collider.
     
  6. dayone

    dayone

    Joined:
    Apr 9, 2014
    Posts:
    4
    It seems that this is the correct answer but it solves my problem partially.
    Playing with that value didn't close the gap but after some low value two objects started to penetrate.
    I believe the main reason is, I am moving the circle too fast to detect the collision at the edge.
    I guess, I have to live with a small gap or objects have to penetrate each other.
     
    Last edited: May 22, 2015