Home > Back-end >  box collider getting caught on tilemap collider
box collider getting caught on tilemap collider

Time:08-27

I have a player that uses a box collier and a level that uses tilemap colliders. The folowing code is drawing contact points with the wall:

    int numContacts = mBody.GetContacts(levelFilterGround, contactPoints);
    for (int i = 0; i < numContacts; i  )
    {
        Debug.DrawRay(contactPoints[i].point, contactPoints[i].normal * 0.4f, Color.red, 0, false);
    }

*for these purposes levelFilterGround is set to no filter (it is a ContactFilter2D)

player stuck on wall

As you can see the player is "standing" on one of the individual "boxes" that make up the wall. For reference here is the players collider and rigidbody:

player's rigidbody

player's collider

And the faulty tilemap collider:

tile map collider

I appoligise for my extensive use of images here and I know it is bad practice but I don't know how else to include this information, if anyone does please tell me.

Anyway, this is pretty problematic because a platformer where you can stand on and jump up walls isn't really a platformer.

*clarification, this issue doesn't always happen, only once every few jumps into the wall, it seems to happen more often with lower default contact offsets, but I might just be imagining it.

If anyone else has had and solved this problem please tell me what you did to fix it so that I can fix this bug.

CodePudding user response:

I think you are looking for the Composite Collider 2D. You can add it with the tilemap Collider, which will join all the individual collider boxes. change "OffsetDistance" if there is space between your collider boxes.

  • Related