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

Side "collision" on one way platforms on tiles.

Discussion in '2D' started by Dmumzo, Dec 20, 2019.

  1. Dmumzo

    Dmumzo

    Joined:
    Nov 28, 2019
    Posts:
    16
    I have a tile map with the following components:
    -Tilemap
    -Tilemap renderer
    -Tilemap collider 2d (Used by effector ON)
    -Platform Effector 2d (Use one way ON, Surface Arc=1, Side Arc=0.

    In my scene I have a platform made with those tiles.

    I also have a player Object with a Boxcollider2d. This player can run left and right and falls because of gravity. The player is standing over the platform. When I press play, the player falls onto the platform. If I debug.log a collisionEnter2d, it returns that the player and the platform have touched. So far so good.

    When the player runs to the ledge of the platform (lets say the right ledge), he starts falling. A debug.log a collisionExit2d retuns that the player and platform no longer collide. So far so good.

    Now, If I immediately move to the left just after starting falling, so that the player moves down and left and "goes through" the side of the tile, a debug.log returns that the player and platform collide, even though there is no visible collision between the two! Why does this happen? Is there a way to prevent that "collision" from happening?
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,623
    No, your code returns the fact that you had a collision script callback in this instance because there is a contact with the platform but the PlatformEffector2D has disabled the contact so there's no collision response. You can verify the fact that a contact has been disabled using: Collision2D.enabled.

    In short, when a contact is disabled, this flag shows that. If you want to ignore disabled contacts then use this to determine that.

    Note that you can also check this per-contact although that's fairly specialized usage: ContactPoint2D.enabled.
     
  3. Dmumzo

    Dmumzo

    Joined:
    Nov 28, 2019
    Posts:
    16
    Thank you!