Search Unity

Tilemap Collider 2D Issue

Discussion in '2D' started by Rabagast, Nov 18, 2018.

  1. Rabagast

    Rabagast

    Joined:
    Jan 30, 2013
    Posts:
    78
    Hi!

    I haven't used the build-in 2D tilemap editor for Unity that much, but I have an issue. I don't know if this is a known problem or a bug or something.

    My game is a 2D platformer. I use Tilemap Collider 2D and Composite Collider 2D and Platform Effector 2D for jump through platforms.

    When my player jumps through a platform, but doesn't get on the top of the platform and fall down again, the player gets stuck inside the collider. See the screenshot.
    I figured out that I could change Geometry Type from Outlines to Polygons, then the player doesn't get stuck inside the collider, but then another issue appeared. The player gets stuck between the tiles. Like it does when you have all the tiles separate.

    I don't know what to do. This should not be a problem. Any suggestions?

    Btw. I don't know that much code. I use Playmaker.
     

    Attached Files:

  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    Enable PlatformEffector2D.useOneWayGrouping. This ensures that contacts from a collider all stay in sync (are grouped) when using one-way i.e. when a contact is disabled, all subsequent contacts are automatically disabled too. This is very important if the collider is made up of many shapes as each can produce a contact the physics system will try to solve.
     
    Fancy_Mancy and Codeopold like this.
  3. Rabagast

    Rabagast

    Joined:
    Jan 30, 2013
    Posts:
    78
    Hi!
    Thanks for the answer. It works, but I got another issue, when I change the size of the player collider from 0.32 to 0.16.
    Then I got the same problem again. The player is stuck inside the collider.
    I need to have the x-size of the collider smaller than the player or else the player will just walk over a platform gap which is 0.32 or 32 pixels wide.

    Is there a way to solve this?
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    If you're using outline mode then they are simply lines, there is not inside of the collider so all edges are treated as separate surfaces. If you're shrinking your player so that it can fit "inside" an outline box without being in contact with any of the edges then the platform effector isn't going to be of use to you. For one-way grouping to work, you need at least one contact at all times for the other contacts to follow so if you get inside the box on the way down but have no contacts then hit the "bottom" of the box then it is treated as a surface. It has no way to differentiate it.

    To get around this, your player box needs to extend vertically so that it is always in contact with a top/bottom edge of a platform collider.
     
  5. Rabagast

    Rabagast

    Joined:
    Jan 30, 2013
    Posts:
    78
    Well, I can't extend the collider box too much vertically, even if I extend it maximum, it works better, but not 100 %

    I think this could be done better in Unity. I mean, I have seen games from the 80s and 90s with perfect jump through. Unity should have better platform effector which should work better with the tilemap collider.

    I tried to add tiles manually in the scene. Add 3 edge collider on the tile. Top, left and right. And then add platform effector and change Surface Arc from 180 to 90, this works very well, but then I need to add all the tiles manually in the scene which is a lot more work.

    I think Tilemap should have more options when it comes to colliders. For example use edge colliders.

    If I want to get around this, I think I need to use code or Playmaker.

    But thanks for the help anyway. :)
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    There are also lots of Unity games with "Perfect" jumping too.

    What do you mean by "better" specifically? The platform effector knows nothing about the tilemap collider or any other collider, it's job is simply to look at contacts and it does that well. I believe you're having other issues here.

    Again, what specific "more options"? For edges, that's what the composite collider is doing already but this is the source of your problems AFAIK. Using edges as an outline does not produce a closed (solid) shape so you can contact interior edges. From what little I've gathered from the single screenshot and description I am guessing this is indeed what's happening here. The grouping option gets around this but also won't help if your character can sit inside the tile without touching it.

    If you think that's necessary but to be honest I'm still not sure exactly what problem you're having here. Remember, I'm only going on a single screenshot and a simple description. Maybe if you post more info on what you're seeing I can help you further.

    In summary, I am "guessing" that your character is smaller than a tile which in itself is unusual and this is the source of your problems. Can you post a screenshot at the moment the problem occurs and please turn on the collider gizmos so I can see where the collider outlines are. One way of making this easier is to go into 2D physics settings and enabled "AlwaysShowColliders" and even "ShowColliderContacts". You can also pause and see the contacts in the inspector by going to the respective collider/rigidbody and unfolding the "Info/Contacts" option there.

    In the end, the solution is to ensure that you are always in contact with the inside of a tile.
     
  7. Rabagast

    Rabagast

    Joined:
    Jan 30, 2013
    Posts:
    78
    Hi!
    I'm sorry, you're right that the tilemap use edge collider. And it does that well of course.
    What I mean with more options, well, there should be possible to adjust the collider. Like you can with another tilemap editor called Super Tilemap Editor. What if the tile is not square? How will tilemap handle that? For example spikes. Will the collider be exact? Like follow the shape of the spike?

    What do you mean that my character is smaller than a tile? It needs to be smaller if I don't misunderstand.

    I can make a video tomorrow, so you can see. It's better than a screenshot. It's very late now. :)
     
  8. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    You don't have to have a square collider, you can have any collider shape you like including a custom one.
     
  9. Rabagast

    Rabagast

    Joined:
    Jan 30, 2013
    Posts:
    78
    Hi!

    But how can I add another collider shape for the tilemap? I only see the tilemap collider 2D and it's no options there for any other shape.
     
  10. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    The collider shapes are set-up in the tilemap tiles themselves. Each tile has a collider type i..e. sprite or grid with grid producing a collider shape the same as the grid shape whereas the sprite uses the physics shape from the sprite that the tile uses (edited in the sprite editor).

    The tilemapcollider2D is just a collider component, each tile isn't a separate component; that would be prohibitively expensive. Each tile produces collider shapes that are contained within the tilemapcollider2d.
     
  11. Rabagast

    Rabagast

    Joined:
    Jan 30, 2013
    Posts:
    78
    Hi!
    I'm not 100 % sure what you mean. How can I set up a custom collider on the tilemap? I have a tilemap collider 2D used by Composite and a Composite Collider. But I can't set up any other collider shapes there.

    Btw. I found a way to make these jump through to work. :)
     
  12. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    Have you watched any Tilemap tutorials (lots around) that tilemap discuss collision? I would recommend it rather than me trying to describe it here. Also, there’s an overview in the manual.
     
  13. Rabagast

    Rabagast

    Joined:
    Jan 30, 2013
    Posts:
    78
    Ok. I will try that. Thanks for all the help. :)
     
  14. Rabagast

    Rabagast

    Joined:
    Jan 30, 2013
    Posts:
    78
    I watched some tutorials, and I got it to work. :) But I also discovered some other things like brushes, tile rules etc. Why is this not included in Unity by default? And where can I find the 2D Extras where all this is included?
     
  15. Rabagast

    Rabagast

    Joined:
    Jan 30, 2013
    Posts:
    78
    I found the 2D Extras Assets. :)
     
    MelvMay likes this.