Help translate player go.get_position() into tilemap id

I’m pulling out my hairs already. I just found out that sprite origin is exact middle instead of pixel corner and that makes it harder to get the precise position. I tried a function like this, at first, it kinda worked.

--Get Tile ID from tilesource
function tile_id(inst, x, y)
	local tile = tilemap.get_tile(inst.SOLIDMAP, inst.SOLIDLAYER, math.ceil(x/TILE_SIZE), math.ceil(y/TILE_SIZE))
	return tile
end

Here’s the function I use:

local TILE_SIZE = 16

function world2tile(pos)
	return vmath.vector3(math.floor((pos.x + TILE_SIZE) / TILE_SIZE), math.floor((pos.y + TILE_SIZE) / TILE_SIZE), pos.z)
end
3 Likes