Tilemap collision question

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

Let’s say I have a tilemap with collidable tiles, and a player sprite with a collider of the same size (in this case, 16x16). My player is unable to fit between a corridor of tiles with one tile space between them. For example: Tilemap Collider example

I can make the player a little smaller, and make its collider 14x14 for example and it will fit through, but then theres some wiggle up and down with between the tiles. I’m wondering if there’s something I am missing, or if someone has a creative idea on how to allow the player to fit through spaces like this. Thanks!

:bust_in_silhouette: Reply From: eons

If you want a stepped behavior try the stepped() and Vector2.snapped() methods to fit a Node2D in a grid when movement ends.
You can use that too after a collision with the tilemap to center the node on a tile.

Remember that you need to slide along tiles too (the kinematic character demo uses a simple slide technique), diagonal movement will keep it stuck with simple move.

EDIT: And forgot, in a kinematic you can set the collision margin, no need to shrink the shape.

Maybe I didn’t explain it clearly. This is a top down game, like zelda, with not-stepped movement. Player can move freely over the map, not tile to tile. I don’t think sliding comes into play here, it’s more that a 16px high collider can’t slide between a 16px high gap, I’m guessing because each corner corrects before the player can get in there. Unless I’m missing something else here.

jonathanh | 2016-10-20 04:19

In general, the hitboxes on topdowns are smaller than the tightest gap the player should be able to pass (usually a door) to prevent bad mechanics feelings.

Try with a small negative collision margin, that may push it a little but let is pass between tiles while keeping detection zone big.

You can also have a small shape for collisions and a child area for detections (like to interact with other objects).

eons | 2016-10-20 14:40