I am experiencing a strange issue regarding 2D colliders. Most of the time, everything works fine, but there is a case where the player is not repelled by an obstacle but rather pulled directly into it. And I can not explain why this happens. I am using the TileMap Component from 2DToolkit to generate the colliders. These all are of the type EdgeCollider2D and the player uses a BoxCollider2D and a Rigidbody2D for movement.
I made a quick video of the issue and my setup here:
(it has annotations to highlight what’s going on)
Any idea what’s happening and what can cause this?
If it’s a tile-based game i’d use box colliders for tiles, and circle collider for player. I’ve never used edge collider either, isn’t it for this case worse option to polygon collider?
The edge colliders are created by 2dtk. I think they do this, because they can merge multiple colliders into a single collider for performance reasons.
An edge is a line, and your object could technically be on either side of that line, not just ‘outside’ … if your object gets close enough to the middle of overlapping, it could be considered to really exist on the other side and then the physics system is going to try to push it away toward the ‘inside’ of the tile. You would be technically better served with box colliders or polygons (slower), although edges are I think more efficient and require less of them. You just need to find a way to maybe ‘detect’ proximity to the surface and take actions if things get messy - maybe with some raycasts or extra triggers attached to the player or something.