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0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,},
{"a" ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,"b" ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,},
{0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,"c" ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,},
}
Like if a and b are on the same row, they belong to each other and if the the c and b y are in the same collum, thats all good, but it doesnt work for whatever reason, wich is why i need help. It gives me 4 colliders, one with negative width, when i expected 2.
Code: Select all
local aTable = {}
local bTable = {}
local cTable = {}
for y, xs in ipairs( instance.map.collision ) do
for x, value in ipairs(xs) do
if value == "a" then
local a = {aX = x, aY = y}
table.insert(aTable, a)
end
if value == "b" then
local b = {bX = x, bY = y}
table.insert(bTable, b)
end
if value == "c" then
local c = {cX = x, cY = y}
table.insert(cTable, c)
end
end
end
for i, a in ipairs(aTable) do
for i, b in ipairs(bTable) do
for i, c in ipairs(cTable) do
if a.aY == b.bY and b.bX == c.cX then
local body = love.physics.newBody(world, a.aX * instance.map.tile_width - (b.bX - a.aX) / 2, a.aY * instance.map.tile_width - ( c.cY - b.bY) / 2)
local s = love.physics.newRectangleShape((b.bX - a.aX) * instance.map.tile_width,( c.cY - b.bY) * instance.map.tile_height)
love.physics.newFixture(body, s)
print("Collider at X/Y:" .. a.aX * 16 .. "/" .. a.aY * 16 .. "with the width/height:" .. (b.bX - a.aX) * instance.map.tile_width .. "/" .. ( c.cY - b.bY) * instance.map.tile_height )
end
end
end