Having issues with Tilemap Collider + Composite Collider

Apologies if this is a beginner’s issue, I just started out with Unity a couple of weeks ago.

I keep having problems with player movement whenever I use the Tilemap Collider. The problem is that whenever the character moves to the right on the tilemap tiles, it is as if the player is constantly colliding with the tiles that I placed on the grid, causing a stuttering / jittering effect. This is probably due to the player jumping between different animations (my guess is that it switches between the walking and falling animation). The effect is quite subtle in the clip, but in my editor it basically looks as if the player is having a seizure.

A couple of things to note are that this only occurs when the player moves to the right on tilemap tiles and the issue does not occur on “plain” game objects such as 2D squares (white platform above).

Some things I’ve tried with no avail:

  • Replacing the player’s box collider with a capsule collider (same result with a polygon collider).
  • Working with the standard tilemap collider without the composite collider. While this removed the jittering, it seemed to create spontaneous “invisible walls” that the player occasionally got stuck on (appeared infrequently, sometimes at the same spots, sometimes at different spots).

The only workaround I have for the moment is to apply a box collider manually to the entire row of tiles. While I’m happy that it resolves the issue, it’s not an optimal solution in the long run. Am I missing something obvious here?

P.S. The player’s rigidbody settings are set to Continous Collision Detection and Interpolate.

Never apologise for being a beginner. Everyone is at some point.

I won’t go too deep into the reasons but all physics engines suffer from these kinds of ghost collisions. It’s mainly related to the fact that each of these “boxes” are different shapes and whilst you intend for them to be a continuous “top” surface to move over, the physics engine sees them as individual things and occasionally catches a corner/side so you get a physics response you don’t want.

The 2D physics engine provides edges which allow you to create larger-scale structures which do produce a single continuous surface by chaining edges.

Two things provide this: the EdgeCollider2D and the CompositeCollider2D when using Outline geometry-type. The only reason you’d ever use a CompositeCollider2D on a TilemapCollider2D is to solve this issue because it has its drawbacks. If you are using a CompositeCollider2D but have left it in Polygon geometry-type then you’re not getting advantage, only drawbacks.

In short: Use Outline geometry-type (https://docs.unity3d.com/Manual/class-CompositeCollider2D.html).

Hope this helps.

1 Like

Thank you so much for your quick reply and tips. I’ll try it out! :slight_smile:

1 Like

Good luck.

1 Like

I have the same issue. I use compositeCollider2D and the geometry type is outline. But still the player gets stack on walls.

Then you have a completely different problem (the OP was not “stuck” on walls) that isn’t related to ghost collisions so please don’t necropost, create your own thread for your own problem rather than assuming it’s the same problem. If you had the same problem, the solution would be the same!

Figure out why you’re “stuck” on wall by debugging the Rigidbody2D velocity etc; maybe it’s friction or your movement code is constantly putting the colliders into overlap with the wall and using discrete col-det means the solver is spending all its time constantly trying to remove you from the wall (self imposed).

Thanks.