It seems like it has something to do with the tilemap. I reassigned the tiles in LDtk.get_layers while loading level 2, and here are the results. An invisible collision area that matches the height and width of this 16x16 tile that the player should be colliding with, but is clearly not. Sometimes it happens with other tiles, though. I also saw it happen with the tiles in the lower-left of the level, lower-right of the level, and to the upper-right of the 16x16 tile that's in the gif.
Here is the modified LDtk.get_layers function
function LDtk.get_layers(level_name)
local level = _levels[level_name]
local tileLayer = level.layers.Tiles
local height = #tileLayer.tiles / tileLayer.tilemap_width
if level_name == 'Level_2' then
tileLayer.tiles = {
2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,2,2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,2,2,2,2,2,2,2,2,2,2,
2,2,2,1,1,1,1,1,1,1,1,1,1,1,2,2,1,1,1,1,1,1,2,2,2,
2,2,2,1,1,1,1,1,1,1,1,2,2,2,2,2,1,1,1,1,1,1,2,2,2,
2,2,2,1,1,1,1,1,1,2,2,2,2,2,2,2,1,1,1,1,1,1,2,2,2,
2,2,2,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,
2,2,2,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,
2,2,2,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,
2,2,2,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
}
end
print(level_name, tileLayer.tilemap_width, height)
for row = 1, height do
local things = {}
for col = 1, tileLayer.tilemap_width do
things[#things + 1] = tileLayer.tiles[(row * tileLayer.tilemap_width) + col]
end
print(table.concat(things, ','))
end
if not level then return end
return level.layers
end