Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Tilemap Collider 2D issue

Discussion in '2D Experimental Preview' started by Darinth, May 31, 2017.

  1. Darinth

    Darinth

    Joined:
    Apr 6, 2017
    Posts:
    4
    I've spent several hours trying to figure out what the ultimate root cause for this is to no avail. I've been able to determine what appears to be a valid workaround, but no an actual solution. In preview 3, my CharacterController2D that I made works beautifully. In preview 4, it still mostly works but was occasionally failing when going up slope made by tiles in a TilemapCollider2D.

    upload_2017-5-31_14-50-17.png

    upload_2017-5-31_14-49-5.png
    In the images above, there are 2 zombies (the boxes with green arrows in them) with my CharacterController2D attached to them who are walking up and down slopes. The lowerright zombie is going up and down a slope formed by a tile collider 2D. The tile collider in the top is much more akin to how my actual tile were originally setup. Those slopes have more tiles to them, but I started removing pieces to see if I could identify the issue. The top image results in the lowerright zombie regularly glitching through the collider. The lower image does not. Removing those solid blocks that occupy the internal/underside of the slope seems to fix the issue. The upperleft one is running on a single edge collider, one of my tests trying to figure out what was going on. It runs perfectly fine.

    Once again, all of this worked perfectly fine in preview 3. It looks like something changed with the way that tilemap collider 2d generates it's mesh between preview 3 and 4 such that boxcasting is now detecting (or not detecting?) collisions in some of these situations where as far as I can tell it shouldn't be.

    FYI, the character controller runs on the basic principle of box casting and then using impact normals and vector rejection to adjust trajectory and try again. If there's more information I can provide, let me know.
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,324
    The TilemapCollider2D doesn't create a "mesh", it creates separate shapes for each tile. Each shape has to be convex.

    Between preview 3 and 4, the only thing that changed was a bug fix to ensure that you can add/remove individual tiles and those specific shapes were created and destroyed. There's no fundamental change in how shapes are created, that is at a much lower level and is shared with other colliders.

    Just like other discrete colliders next to each other, them being next to each other does not produce a continuous surface and it's subject to the usual problems of colliders "catching" when moving between them.

    This is what the CompositeCollider2D can be used for, blending multiple collider shapes into a single continuous surface when using "Outline" mode i.e. edges only.
     
  3. Darinth

    Darinth

    Joined:
    Apr 6, 2017
    Posts:
    4
    For intellectual curiosity, I'd really like to know what's going on. The code worked in preview 3 flawlessly, but was failing in 4 but adding a composite collider to it has solved the issue. I maintain a skinwidth for boxcasting to avoid the issues related to typical catching and to avoid erroneous initial collision with the ground. I wonder if something happened between 5.5 and the 2017 preview that this is built on which changed how the colliders all work together.
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,324
    It's no good going back and forth on this. If you can isolate a specific (BoxCast?) that does something you didn't expect then a bug report would be great. Note that simplifying the report as much as possible is essential.