Tile ID for collision?

Hi!

I’m new to Defold, and trying to play around with a tilemaps. Currently, I’m trying to create a coin which you can pick up, using a tilemap. I’ve got collisions working, but I’m currently trying to understand how to detect the tile ID of the collision.

So, if I have a player which is receiving collision messages – or a tilemap which is receiving messages – what is the best way to get the tile of the collided object?

I tried playing with get_position(), but since the player object can be outside the cell when it collides, this ends up with lots of off-by-one errors :slight_smile:

I feel like I must be missing something obvious, and would appreciate any help :slight_smile:

Thanks!

  • Chris

Hmm, ok, so the coin is part of the tilemap? I think that approach will become quite messy since it’s going to be tricky to determine the exact tile location. I think it’s better to make the coins normal game objects and place those separately.

1 Like

Okay, it’s good to know I’m not missing anything obvious :slight_smile:

I was hoping that I would be able to generally use this approach – e.g. add a tilemap block, and when you collide with it, change state. (e.g. walk through an invisible tilemap block to change game state as a way of passing a ‘gate’, or step on a “P-Switch” like block; block is removed, and the game state is changed as a result.) But if this seems wrong, probably means I need to learn more about Defold to figure out how to do what I want :slight_smile:

(I sort of liked this because it was easy to just drop items quickly into a tile map using the visual editor without having to worry about positioning, etc. But if I’ve got to do more work – so be it :))

Thanks for the response!

You could definitely go about the way you describe but there’s little point in using the physics engine for collision. It’s simpler to calculate which tile the player is on based on her position. And if you’re on a tile you collide with it. :slight_smile:

1 Like

Well, ok, as @sicher wrote, you can still query the tilemap for tile ids but then it’s probably better not use the physics system and instead do it the old-school way that platformers used to solve this problem.