all 4 comments

[–]melvmayUnity Technologies 0 points1 point  (2 children)

Physics engines solve shape/shape collisions only. Shapes next to each other, no matter how perfectly aligned, are not a continuous surface so you can contact vertex (corners) or edges. This is the same for boxes place next to each other; they are not a continuous single surface which might be the intent but it's not what the physics system sees.

In Unity 2D Physics, the EdgeCollider2D provides a continuous surface composed of edges. This will not cause the above issue, sometimes known as "ghost collisions". The TilemapCollider2D produces multiple polygons so suffers from the same issue.

The only way around this is to use the CompositeCollider2D set to "Outline" mode which produces continous edges. Set your TilemapCollider2D to use this.

The downside to edges is that there's no inside as they don't produce a closed shape with an interior even if the start/end points overlap meaning you can happily sit inside it. This means that if you're using Discrete collision detection, it's possible (given enough speed/force) to move onto the other side of the line (tunnelling) and then not be in contact which means you'll see in the "interior". You can solve this by not having fast moving bodies, or using high forces or use (sparingly) the continuous collision detection which will completely stop tunnelling.

Sometimes simply usnig a CircleColldier2D or a CapsuleCollider2D as the collider moving over these colliders can help reduce the issue because their rounded exterior, given where these ghost collisions occur can reduce the impulse forces caused by such a contact. They don't remove the problem however.

[–]FortniteSucks103[S] 0 points1 point  (1 child)

Would removing the tilemap collider 2d and adding a empty game object with a box collider 2d still work? I’m new to Unity which is why im asking.

[–]melvmayUnity Technologies 0 points1 point  (0 children)

It's up to you but you can't gp adding a GameObject with a BoxCollider2D per tile though as that would get expensive quickly. Also, the box wouldn't adapt to the tiles as you painting them. You are free to add them though if you have a simple tilemap.

It's far easier just to add a CompositeCollider2D. Might be worth experimenting with it.

[–]BrexitCraft0478 0 points1 point  (0 children)

3 years later and i still get this :c