How to get x,y of a tile on tilemap based on position of another game object

so i want to use the x y(2.7374673, 6.3748372, 0) of the player and change it to get the x y on the tilemap(4,-3) to be used to react to activators and doors, how do i do that?

1 Like

You can use a collision object to detect when the player touches a certain type of tile: https://www.defold.com/manuals/tilemap/#_tile_source_collision_shapes

1 Like

Are you interested in something like this?

function tile_id(inst, x, y)--inst is self
	x = math.ceil(x)
	y = math.ceil(y)
	return tilemap.get_tile(inst.TILEMAP, inst.TILEMAP_LAYER, math.ceil(x/TILE_SIZE), math.ceil(y/TILE_SIZE))--TILEMAP & TILEMAP_LAYER is saved as layer on object
end

That’s how I use inside LUA module, but you can config as you want.

4 Likes

Yeah but I have the same door tile that goes to different places right so I cant just use the collision groups

Hm Im not sure but i think so thanks for now

This function converts world position to tilemap position and return ID of tile.

1 Like

The function assume the tilemap is at origin and not rotated, right?

1 Like

Kinda. It simply converts world position to tilemap position. In the world, tiles might be 16x16 or whatever, but in tilemap, they are like 1 pixel wide.
You can read a bit more here.

1 Like