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

New Tilemap Collider 2d an Composite Collider 2d issues

Discussion in '2D' started by strawberries036, Feb 26, 2020.

  1. strawberries036

    strawberries036

    Joined:
    Aug 23, 2015
    Posts:
    6
    Hello,
    I'm doing a 2d platformer using Tilemaps, I worked for a while on the 2018.3 version of Unity and built all my levels using Tilemaps colliders + composite colliders.

    I changed to version 2019.3 few weeks ago and made a lot of work and features. All my levels worked perfectly, but I noticed something... When I disable the Tilemap gameobject ( wich are all the platforms of my level) and enable it again, then the generated triangulation of the composite collider is changing.

    On top of that the physics and collision are not working well anymore. My character is bumping and stop at the edge of a platform randomly even if it's just a rectangle and not a complex composite shape.
    The character (a rigidbody2d) seems to "fall" when I move left, I mean the collision is working but the velocity is constantly going a bit under 0 in the Y axis and break a lot of my gameplay mechanics.

    What I noticed is that the Tilemap Collider and The Composite Collider changed in 2019.3, there is new parameters that can be changed: The offset distance and the extrusion factor. Theses things were existing at all in the previous version. So it seems that it's the source of the problem.

    - I tried to rebuild a tilemap grid from scratch, but I have the same issues.
    - I imported the old levels from my backup version of unity 2018.3 into the new one and everything works fine until I try to edit the Tilemap again. (and I need to build new levels so it will not help me)
    - I tried to save preset of the Composite Collider 2d from my 2018.3 version into the new one, and it doesn't work.
    - Everything works fine with 2d box colliders as platforms, so one of my solution would be to redo all of the platforms and walls collisions with boxes ( and it's going to be hours of work and lose the interest of using Tilemaps)

    So if someone know what happenned with this new colliders I'll be happy to try any suggestions.
    I was wondering if there is a way to use the old unity component into the new versions, because that could definitly solve my issue.

    Thanks
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,623
    Actually they were, they're just now exposed. It's not a "new" component at all.

    If you feel there's a bug then I would ask that you submit a bug report.
     
    strawberries036 likes this.
  3. strawberries036

    strawberries036

    Joined:
    Aug 23, 2015
    Posts:
    6
    Thanks for your answer, Do you know where I can report the bug?
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,623
    Use the Unity bug reporter.
     
  5. strawberries036

    strawberries036

    Joined:
    Aug 23, 2015
    Posts:
    6
    I sent the bug report.
    Also made a quick test with an empty scene.
    On the left the platform with tilemap collider and on the right a box collider.
    when press play the colored squares are falling and I checked there Y velocity when moving horizontaly on the platform.
    The tilemap collider as definitly a problem and changes the Y velocity of an object when the boxcollider doesn't.
    Here is a screen grab:
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,623
    Please give me the case number.

    I really don't understand what you're saying here.
     
  7. strawberries036

    strawberries036

    Joined:
    Aug 23, 2015
    Posts:
    6
    Sure it's case 1223975!

    Sorry the sentence is a little bit confusing.
    This scene has nothing in it.
    The two squares (orange and blue) are rigidbody 2d affected by gravity (simulated).
    The orange platform is a tilemap collider2d with a composite collider 2d set to static
    The white platform is a box collider 2d set to static.
    When I play the game the orange square is falling on the orange platform (because of gravity) and the blue one is falling on the white platform.
    Then I change theire x.velocity with a get axis. So i can move left or right.
    When the white cube is moving on his plaftfom, his Y velocity doesn't change and it's logic.
    When i do the same with the orange one, his Y velocity is changing (the number on the picture) and it's anoying because it shouldn't. It's like the orange square is constantly falling but he is on the platform.

    Hope it's a bit a bit clearer.

    Edit:
    I just tried the same setup in v 2018.3.14f1 and the orange square Y velocity stay at 0 when I move it on the Tilemap platform.
    Now I'm pretty sure that it's a bug coming from the new update of the tilemap collider 2d and the composite collider 2d components.
     
    Last edited: Mar 1, 2020
  8. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,623
    So I just took a look at your project and it seems you're just expecting velocity to be zero when moving horizontally but that isn't guaranted and you shouldn't ever expect that. Sometimes it might be but it isn't some hard guarantee as the physics doesn't work like that. The fact that you stay on a platform is because a floating point solver is carefully balancing gravity with the overlap contacts of the surface. The position should stay relatively stable but again, it's no guarantee it'll be exactly the same.

    I think you're confused over scientific notation. -6.750226e-06 isn't -6.750226 meters/sec, it's -0.000006750226/sec or 6.750226 micrometers (μm)/sec. I read that a human hair is around 17μm to 181μm in diameter.

    More importantly, floating-point isn't infinitely precise and small floating-point variations will happen. Look at the Y positions of your objects, they're both not changing. You should never compare floating point values with zero in your logic. You should check "near zero" or near the value you want. There's plenty of info on the Internet about comparing floating point values.

    I think all you've done is make your code succeptable to this. The difference isn't some "new components" you're refering to (which isn't the case), it's the fact that the default for the CompositeCollider2D property of "Offset Distance" changed at some point to something smaller. Try setting that to 0 and it'll clamp to "5e-07" rather than "5e-05". The thing is, this might give you approximately zero Y velocity but if you move or reorientate the platforms, you'll get non-zero velocity again so you should ensure that this doesn't matter.

    Just don't do absolute float comparisons.
     
    Last edited: Mar 1, 2020
  9. strawberries036

    strawberries036

    Joined:
    Aug 23, 2015
    Posts:
    6
    Thanks again for your help.
    I understand now! So my scripts should'nt use the Raw velocity of the character but a rounded version of it.

    But what about the collisions? Now the character is bumping (and stop moving ) on the top corners of the platform randomly.

    Is there a way for me to install the components from 2018 in the 2019 version as custom component?
     
  10. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,623
    In short yes but to be clear, this has nothing to do with physics specifically and everything to do with how you handle floating-point values. You should read up on this subject. Here's one of many examples: https://floating-point-gui.de/

    Tell me what you want to do with the Y velocity (what check do you want) and I can give you an example of how to do that. You cannot simply do "if (rb.velocity.y == 0f)" as it might be "near zero" due to floating-point error.

    Could you explain what you mean by this and/or how to reproduce what you're referring to using your case? Maybe show a video.

    They have not changed apart from the default value I mentioned earlier but as I explained you can change that. Honestly, I do not yet see the problem you're trying to avoid, I wish I did.
     
    Last edited: Mar 2, 2020
  11. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,623
  12. strawberries036

    strawberries036

    Joined:
    Aug 23, 2015
    Posts:
    6

    This what I mean by bumping in the corner (the orange square is blocked by the end of the platform).

    I'm using the Y velocity to detect if the character is falling. When it's under 0 it activate a bool variable.
     
    Last edited: Mar 2, 2020
  13. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,623
    I just ran your bug report and I don't see this. Can you tell me how to set that up or send me the project?
    https://gyazo.com/fbb5c0789691acd51f115e0044ea9286

    Turn on contact display and see if you get contacts pointing sideways. They should be pointing up or down. Note you can also see all the contact information in the Inspector if you open the "Info" panel under "Contacts".
    https://gyazo.com/e1251733d9504e0ebdfe906069c140b9

    Just hide the sprites and show the colliders. You can also turn this on for all colliders in the same place as above.

    Finally, an important point you're missing is that you're NOT colliding with a CompositeCollider2D or a TileMapCollider2D because the physics knows nothing about those at all. Physics only knows about circle, polygon, capsule and edge. In the test scene in your bug report, BOTH platforms are made of a single polygon shape each same as the boxes moving on them. They are identical. The only difference can be is that you're doing some playmaker logic that's causing this.
     
    Last edited: Mar 2, 2020
  14. GreatGardna

    GreatGardna

    Joined:
    Jan 9, 2020
    Posts:
    14
    Changing the Offset Distance to zero worked, Thanks MelvMay I've also experienced some problems with the composite collider 2D. My character isn't working quite well since I updated Unity from 2018.4.22f1 to 2019.4.17f1