Search Unity

Tilemap Collider 2D Bug (Mesh not generating correctly, falling through floors/walls)

Discussion in '2D' started by Igotlazy, Feb 11, 2020.

  1. Igotlazy

    Igotlazy

    Joined:
    Jan 15, 2018
    Posts:
    12
    https://i.gyazo.com/544755c5ba2e988d89d7f67896a5d53b.mp4

    So I'm using Tilemap Collider 2Ds to define the levels of my 2D Platformer. For some reason however, in these very specific locations, the mesh doesn't generate properly and basically acts as though a wall/floor doesn't exist. This only happens if I transition into the scene that has the Tilemap Collider, not if I start the game in the scene (happens in build as well).

    In the clip I showed, every other wall in the level functions perfectly. It's only this wall. I have had this occur to me in a different scene with a floor segment. If I change the level geometry, the bug usually fixes itself.

    I am using Tilemap 2Ds with Composite Collider 2Ds and Static Rigidbodies. I have also set the gameobject itself to Static, and the geometry type on the Composite Collider to Polygons. The Tilemap colliders are quite large and complex, and are often disjointed as well.
     
  2. Tom-Atom

    Tom-Atom

    Joined:
    Jun 29, 2014
    Posts:
    83
  3. Igotlazy

    Igotlazy

    Joined:
    Jan 15, 2018
    Posts:
    12
  4. Tom-Atom

    Tom-Atom

    Joined:
    Jun 29, 2014
    Posts:
    83
    Hmmm... that's pitty.... In my level it works well now. But I remember, that previously small rearranging of tiles produced different collider with bugs in different places. So, I might be just lucky because of level layout.

    Best would be, if you could report a bug with minimal project attached (I used Unity Repo Project Wizard - https://github.com/Unity-Technologies/ReproProjectWizard to strip unnecessary things) and I also recorded detailed video for them. Better you describe it, higher the chance they will find it quickly...
     
  5. Igotlazy

    Igotlazy

    Joined:
    Jan 15, 2018
    Posts:
    12
    Perhaps the fix only applies to fresh Tilemaps/Composite colliders. The ones I'm using have existed in the project since 2019.2. I'll play around with it.
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    2,314
    The original problem was that the (great) libtess2 library that the CompositeCollider2D uses was producing very small polygons with almost collinear sides and depending on the polygon itself, Box2Ds collision detection algorithms were not producing contacts. We knew this already and detected absolute collinear verts and even allow a small amount of wiggle room so "nearly" collinear but the original bug report shows verts that were outside of this but still Box2D thought they were colinear so we increased it slightly and used an addition metric of polygon area and this fixed all the reports we had where under a special configuration you would pass through the shape.

    Maybe you're creating another one. To be honest, it's a tricky balancing act.

    Whilst these cases are rare, the CompositeCollider2D can produce all sorts of weird configurations so it's why it's appearing there and not in the PolygonCollider2D which also uses libtess2.

    The way forword I think is to perform a better edge-merging for these cases but it can become non-trivial to do.

    We do have another report of this which we've accepted but if you do have a project you could share with the bug reported then please go ahead and created it and send me the case number and I'll see if it's the same.

    As a workaround, maybe you'll get better results if you were to use Outline mode (assuming you can) and/or change the Vertex Distance to smooth out the resultant shapes. As I say though, this is a workaround to keep you moving forward.
     
  7. Igotlazy

    Igotlazy

    Joined:
    Jan 15, 2018
    Posts:
    12
    Do you happen to have a link to the bug you've accepted, just so I can see if it's similar to mine (I'm assuming it's something on the Issue Tracker)?

    I've considered using Outlines, and they do seem to always generate proper geometry, but honestly I'm partially worried about using them. The player should never, ever be inside of these walls, and Outlines makes no attempt to depenetrate them once an object crosses the border. Is there anything to keep in mind/techniques to use with this geometry type in order to avoid cases where entities could find themselves inside the collider? Most Unity tutorials that use Tilemaps Colliders do set the geometry type to Outlines, so maybe I'm stressing for no reason.
     
  8. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    2,314
    I don't have a link for you as it's not public. Let's not assume it's the same thing as that happens all the time. Please submit a reproduction case and send me the case number.
     
unityunity