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. Dismiss Notice

Question Stuck inside a one-way 2D platform

Discussion in '2D' started by fakedev, Jan 31, 2023.

  1. fakedev

    fakedev

    Joined:
    Jan 14, 2023
    Posts:
    10
    I've got a player object with its Rigidbody 2D and Box Collider 2D components. I also have a tilemap with Tilemap Collider 2D, Rigidbody 2D, Composite Collider 2D, as well as a Platform Effector 2D. The last one enables the one-way platform: the player is supposed to jump on the platform from the bottom to the top.

    Here is the expected result:


    However, if the player jump stops inside a one-way tile, it is stuck inside it:


    Since the player had not reached the top side of the platform, I expected it to fall.

    What have I done wrong here?

    What is the most Unity compliant way to solve this issue?
     
  2. fakedev

    fakedev

    Joined:
    Jan 14, 2023
    Posts:
    10
    I'm still surprised by the one-way platform behavior.

    However, there is a workaround: player's collider height has to be bigger than the height of the one-way platform, including its one-way neighbours.

    By increasing the size of the player collider and modifying the level design, the problem can be avoided.
     
  3. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,463
    The tilemap collider acts effectively like an edge collider, not like a box collider. The docs mention that for performance reasons it batches tiles together (since larger levels would result in a LOT of triangles otherwise) and that's the consequence of that.
    Effectively that means this type of collider will never trigger if the player is entirely within it. So the platform cannot differentiate between the player being inside or outside the tile. It just prevents the player from passing through when hitting an edge vertically.

    If you need special passable platforms that are larger than the player, consider objects with box colliders.
     
    Last edited: Feb 4, 2023
    fakedev likes this.