Search Unity

TilemapCollider2D is not working.

Discussion in '2D' started by coolblue2000, Nov 2, 2017.

  1. coolblue2000

    coolblue2000

    Joined:
    May 7, 2015
    Posts:
    24
    I have a player object which has a boxcollider2d and a rigidbody2D and a tilemap with a tilemapcollider2d set to trigger. The issue is that the player object passes straight through the tilemap objects without firing the ontriggerenter2d event.

    If I replace the tilemap with traditional objects with boxcollider2D set to trigger then it all works fine...

    What could be going wrong?

    Edit---------------

    Interestingly the tilemap images do not disappear if I untick the tilemap renderer (which I would expect) but do vanish if I untick the grid. Plus there are no green borders around the tiles which I would expect if they had a collider...
     
    Last edited: Nov 2, 2017
  2. mctyler

    mctyler

    Joined:
    Mar 29, 2014
    Posts:
    3
    I think maybe you had the same misunderstanding of what TileMap does as I did. TileMapCollider creates one collider for the entire TileMap, not individual colliders for each tile. It will generate a collider with geometry merging all the tiles in the tilemap. So I'm assuming your player collider is already inside the TileMap collider and therefore not triggering.
     
  3. coolblue2000

    coolblue2000

    Joined:
    May 7, 2015
    Posts:
    24

    Yes I did sort of expect to see a collider per tile. However this was not the issue. Basically there seemed to be some corruption with the scene so the tile map collisions did not work at all. I deleted the scene, created a new one and the tilemap now works as expected.
     
  4. Yousef_Hadhrami

    Yousef_Hadhrami

    Joined:
    Sep 9, 2018
    Posts:
    4