Tile collision problem
Posted: Fri Jul 26, 2013 2:16 am
I've been making a tile system so that sometimes collision is on, and other times is off.
Then I added a if coli is true function.
I don't get any errors, but collision isn't how I'd like it to be. At some point, when hitting the tile to the left, it works. At others, it moves the player up. Please help me.
Code: Select all
function tile:spawn(x, y, coli, img, width, height)
table.insert(tilem, {x = x--[[int]], y = y--[[int]], coli = coli--[[bool]], img = img--[[string]], width = width--[[int]], height = height--[[int]]})
end
Code: Select all
function tilep:coli()
for i,v in ipairs(tilep) do
if v.coli == true then
if char.x >= v.x - 14 and char.x <= v.x + v.width - 14 and char.y >= v.y - 21 and char.y <= v.y + v.height - 21 then
char.y = v.y - 21
end
if char.x >= v.x and char.x <= v.x + v.width and char.y >= v.y - 21 and char.y <= v.y + v.height - 21 then
char.y = v.y - 21
end
if char.x >= v.x - 14 and char.x <= v.x + v.width - 14 and char.y <= v.y + 21 and char.y >= v.y - v.height + 21 then
char.x = v.x - 14
end
if char.x >= v.x - 14 and char.x <= v.x + v.width - 14 and char.y <= v.y and char.y >= v.y - v.height then
char.x = v.x - 14
end
end
end
end
end