How do I stop collisions along the floor when using a TileMap?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By disousa
:warning: Old Version Published before Godot 3 was released.

I’ve recently started working with Godot (in 2D) making a platformer, and while I have managed to understand most of it, I can’t seem to figure out why this is happening.

I have a map made in a TileMap node, in which the tiles are composed of Sprites with StaticBody2D and CollisionShape2D (rectangle).

My player is a RigidBody2D (character mode) with a sprite and a CollisionShape2D (rectangle).

When I begin the game, gravity pulls the player down against the floor, and the collisions stop him from falling through as expected. But for some reason, when I attempt move the player sideways (walking), the very top of the lateral edges of some of the floor tiles seem to be colliding with the player, and making him stop moving forward. What can I do to fix this?

Thank you very much!

Maybe you should use StaticBody for the tiles instead of Rigidbody, becauses tiles are not supposed to move.

Zylann | 2016-07-16 01:15

My bad! That’s what I meant to write! I’ve corrected my question! Thank you!

disousa | 2016-07-16 01:18

:bust_in_silhouette: Reply From: Zylann

This is most likely due to microscopic gaps between your tiles. Did you make sure the collision shapes you defined in the tileset are perfectly connected? You can do so by enabling the snap grid and set it to the size of tiles, so when you draw collision shapes they will be perfectly connected.

I haven’t done it by that method, but I definitely defined them to be the exact size of the tiles using the extent property, so they should be connected. And I found out that the issue shows up on the boundary of any two static bodies, not just tiles… :confused:

disousa | 2016-07-16 02:14

You are right, it happens with both collision shapes and polygons. I’m not sure if it’s a bug, but it looks unexpected.
As a workaround, you could try to use a CircleShape for your character, or a rectangle with rounded borders. I just tested this and it works fine.
If you feel like it’s a blocking bug you can write an issue on Github: Issues · godotengine/godot · GitHub

Zylann | 2016-07-16 02:46

I had tried that already. But it seems that the character jumps around slightly when hitting the seams. I’ll have to try to find a solution. Thank you so much!

disousa | 2016-07-16 12:17

:bust_in_silhouette: Reply From: martymon

I found your question online because I had the exact same problem. I seem to have resolved it by making sure that I use:

  1. CollisionPolygon2D instead of CollisionShape2D and
  2. Using the snap to grid option (Use snap) when defining the points of the CollisionPolygon2D.

I have not seen my character catching the “seams” between tiles so far.

Hope that helps.