Having problem with Tilemap collision

I think you’re dealing with ghost collisions. see Struggling with kinematic physics ghosting collisions and jittering - Questions - Defold game engine forum —this video shows it working better.

This happens when a sprite moves across tile boundaries because the tile collision objects aren’t one continuous shape but are instead made up of small, tile-sized pieces. As the sprite moves over these boundaries, it catches on them.

The way I’ve handled this before is by checking the position of the collision. For example, if your tile grid starts at position 0,0 and the tiles are 32x32, ghost collisions will usually occur near each multiple of 32. If the collision’s x or y is close to that, I send out a raycast to double-check its status (based on the normal) and then decide whether to discard or use it.

So if detecting a collision on the right and its very close to the tile boundary, send a ray cast a little higher up. if this fails to collide with anything you know its a ghost and can ignore it.

Another option is to skip contact point collisions entirely and create a custom collision system for the main sprite using raycasts. If this is of interest, look at britzl/platypus: Defold platformer engine.

For my platform game, I started with contact point collision, added measures to prevent ghost collisions, but eventually—much later in development—switched to a custom raycast approach for the main sprite. Britzl’s method for handling moving platforms proved extremely useful in my implementation.

1 Like