CharacterBody2Ds stacking on top of each other prevents the bottom one from moving

Godot Version

4.7.1

Question

I have a player and an enemy which are on separate layers that collide with each other. If the enemy is on top of the player or vice versa, whichever one is at the bottom sometimes can’t move. The velocity of the bottom one is still stored and continues moving it after there isn’t anything on top of it.

I have tried adding a safe margin. It worked to some extent, but it still slows down the bottom CharacterBody2D and when there are more enemies in the stack, it completely stops the bottom ones.

“Slide on Ceiling” is enabled for both, all Moving Platform floor layers are disabled.

[edit]
changing the shape of the CollisionShape2D did fix this but I don’t like this solution (I want a square)
[edit2]
decided to go with a CollisionPolygon2D with the shape of a square with a pointy top that extends off by a few pixels (feel free to give better suggestions though since it still doesn’t work that well under many other colliders)

Squares stacking with CharacterBody2D love to jam. The top one becomes a floor/ceiling and move_and_slide eats the bottom one’s movement (velocity can still be sitting there, which matches what you saw).

Better approach for player vs enemy: don’t physically block each other.

  • Both collide with the world/tilemap
  • Player ↔ enemy: no body collision (or only a light push)
  • Use Area2D hurtboxes/hitboxes for damage

Then stacking never traps anyone.

If you need them to push solidly, a tiny bevel/rounded top (what you did) or a capsule is the usual shape fix; pure axis-aligned squares are the worst case for this.