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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

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