[2D] Rigidbody trips when walking


I’m creating a small 2D playformer game in Unity, and in this game I want to have a few moving enemies.
I’ve managed to get the scripts and everything just right, but now the problem is, that it looks like the zombie (the enemy I’m using) seems to fall over at random points during his walk.

I’ve tried moving the ground tiles to flatten it more, making the zombie’s collider box be horizontally flat at its feet, I even tried making an invisible collider box just above the ground for it to walk on, but it still does the same thing every time.

Here’s screenshots on how I have its box collider set up (I took off the trigger collider just for testing purposes):

alt textalt text

I’m completely clueless on what might be causing this problem and would very much appreciate advice from someone more experienced than me.

This is being caused by several adjacent colliders being used for a single contiguous surface (i.e. one box collider per tile); it’s a known limitation of Box2D, the engine that Unity’s 2D physics is based on. The “Why does the character get stuck” section of this article might give a better understanding of what’s happening. While the article goes on to suggest some solutions for Box2D, the fix in Unity is to use an edge collider that runs along the border between solid and non-solid tiles.

As an aside, if you don’t want the zombie to fall over, you can enable the Freeze Rotation option in the Constraints section of the Rigidbody 2D component in the inspector.

This problem from what I can see can’t be fixed. I had a similar issue, but from my research you can’t use BoxColliders 2D, use 4 edge colliders. Also If your player is falling and you don’t want it to in the Rigidbody check off FixedAngle. That might fix the other issue as well but he may start to stop randomly instead.

This is the explaination to why it does that.

This can be solved now using the “Composite Collider 2D”

As @kavanavak answered, Composite saves us! In case people still come here for the same problem. Here’s a tutorial video.

In short, on the object which has tilemap collider 2D component, add Composite collider 2D (also, RigidBody 2D will be automatically added if there is none attached already.) Next, in tilemap collider, check the box “Used by Composite”. Now instead of having a collider for each square, we have a big collider for the whole shape.