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

Change in EdgeCollider2D behavior, 4.6 -> 5

Discussion in '2D' started by Togglesworlh, Mar 8, 2015.

  1. Togglesworlh

    Togglesworlh

    Joined:
    Nov 12, 2013
    Posts:
    40
    I've noticed a change in EdgeCollider2D's interaction with dynamic objects (at least with BoxCollider2D and PolygonCollider2D).

    I have a simple 2D tiled platformer, with blocks made up of EdgeCollider2Ds with five vertices each, essentially creating squares out of four edges. The player is a simple BoxCollider2D (and I've also tried translating it into a PolygonCollider2D with the same shape). Continuous collision detection is turned on (although I used Discrete in 4.6, and I've tried Discrete in 5).

    In 4.6 I had no issues running around on blocks or landing on blocks or whatever. At the very least, I can confirm that what I'm about to describe is not reproducible in 4.6.

    Since upgrading to 5, I sometimes fall through blocks. It's not entirely consistent when just running along the top of a row of blocks, but if I jump and land just on the edge of a lone block, like JUST inside the square, I'll fall through the block and then can move through it to the other side. Once I'm through I can't go back in. The vertices go in order of lower left, upper left, upper right, lower right, lower left. It's fairly straightforward.

    So it's something about falling or walking just inside the edge. And sometimes when I fall through I just get stuck inside the block, with the physics engine not allowing me to exit in any direction, bouncing me back and forth and up and down.

    Either I was using EdgeCollider2Ds incorrectly before or Unity 5 has introduced a bug or Unity 5 treats them differently. Whatever the case, has anyone else seen this? Or does anyone have a solution or alternative way of doing what I want to do?

    Also maybe worth noting is that I'm working with fairly small values, I think? Small enough that the physics "skin" around the box is noticeably large. Like, my player BoxCollider2D is 0.09x0.21. The boxes are 0.16x0.16. Maybe that has something to do with it?
     
  2. Togglesworlh

    Togglesworlh

    Joined:
    Nov 12, 2013
    Posts:
    40
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,411
    I presume you've tried using continuous collision detection?
     
  4. darksire

    darksire

    Joined:
    Dec 16, 2013
    Posts:
    10
    maybe make a physic material to the colliders as sticky ,slippery or bouncy. on your project i presume sticky is good
    Friction 1
    bounciness 0
     
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,411
    The material used won't make any difference. I took a quick look at your project and I'm not sure why that is happening but the use of the edge collider is very odd indeed. If you change that to a BoxCollider2D it should solve your problem.

    I'll dig into this more when I get some free time, it may be related to edge-collider accuracy at very small scales, not sure.

    BTW: You might want to take advantage of the new 'IsTouching' & 'IsTouchingLayers' calls to determine if your character is touching things like ground in your character controller: http://docs.unity3d.com/ScriptReference/30_search.html?q=istouching
     
    darksire likes this.
  6. Togglesworlh

    Togglesworlh

    Joined:
    Nov 12, 2013
    Posts:
    40
    Yep, continuous collision detection is on. In 4.6 I actually used discrete and it was fine, but I made sure to turn on continuous just in case, and it didn't help. ):

    The reason I don't use BoxCollider2D is because a bunch of those tiles lined up will catch the player on the corners. And I've tried solving that issue by using a round player bottom, but then the player hops a little sometimes as he's running around. EdgeCollider2D was the only solution in 4.6.

    That said, I did "solve" the problem by adding a BoxCollider2D as well, and just made it slightly smaller than it should be, so that if the player object does somehow fall into the Edge-box, it'll be subsequently pushed out, and I manage to avoid the sticking/hopping problem when running along a row of tiles. It's... not a great solution, but it's one I'm willing to live with.

    (The best solution would probably be to generate a single PolygonCollider2D for all connected tiles, but that's math I haven't really attempted wrapping my head around, as I mostly just want to make a silly little platformer!)

    I'll look into the isTouching, as well, thanks.

    Thank you for the response!
     
  7. Togglesworlh

    Togglesworlh

    Joined:
    Nov 12, 2013
    Posts:
    40
    Oh I guess I should point out that I generate the edge boxes dynamically from a Tiled (level editor) file, which is why I don't just build the polygon collider by hand.
     
  8. Andreu-Accensi

    Andreu-Accensi

    Joined:
    Feb 5, 2015
    Posts:
    18
    I think I just posted a "duplicate" here as I am experiencing the same as you.
    I am also using edge colliders cause I dinamycally build a tilemap.
     
  9. Togglesworlh

    Togglesworlh

    Joined:
    Nov 12, 2013
    Posts:
    40
    I got a response to my bug report that they're aware of it, so hopefully it'll be fixed soon!
     
  10. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,411
    It has been fixed and (after review) will be in the next available 5.0.0 patch release.

    Sorry for the problem this has caused.
     
    Andreu-Accensi likes this.
  11. Andreu-Accensi

    Andreu-Accensi

    Joined:
    Feb 5, 2015
    Posts:
    18
    Is normal to have bugs with such a big product, but I believe the issue tracker with the upvote system is a great idea to prioritize them.
    Thanks for informing. You are doing a great job with Unity!
     
  12. DutchGuerrilla

    DutchGuerrilla

    Joined:
    Feb 17, 2015
    Posts:
    13
    Oh, that would be cool if fixed. My character was suddenly falling through some of the platforms...I couldn't get a hand on the changes I Made and what could give this problem..Seems to be this bug I quess :)
     
  13. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,411
    It was fixed and released on the 26th March in a patch release: 5.0.0p3.
     
  14. grosssmutttr

    grosssmutttr

    Joined:
    Apr 15, 2014
    Posts:
    168
    I still have the problem that some elements pass through the edge collider and get stuck in it.
    I have an edge collider and a circle collider. The circle collider with rigidbody2d falls down on the edge collider with a rigidbody2d and sometimes the circle collider is "merged" with the edge collider gameobject and so it rotates....

    Using Unity 5.0.0p3 on Windows and tested this on a Nexus 4 with Android 5.0

    Haven't experienced this issue with Unity 5.0.0 official release version.
     
  15. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,411
    That may be related to another change which is that we stopped Box2D from automatically using continuous collision detection whenever a static collider is involved (this was reported by users). That went into 4.6 patch and only made it into 5.0.0p1. Assuming it's off, turn on continuous for the rigid-body on the circle.

    Beyond that, there are no changes I'm aware of that would cause that behaviour.