I check collisions by putting this in love.update()
Code: Select all
for i,v in pairs(enemies) do
for g,h in pairs(bullets) do
v:collisionbullets(h, i, g)
end
end
Code: Select all
function Enemy:collisionbullets(b, i, g)
if self.y + self.height >= b.y and self.y <= b.y + b.height
and self.x <= b.x + b.width and self.x + self.width >= b.x then
table.remove(enemies, i)
table.remove(bullets, g)
end
end
And all of that works just as it should, except for the table.remove part
Basically if it removes the first object from the table, then the now first (which before the removal was second) has it's y value shifted slightly, or atleast that's how I understand it
I kinda resolved it by modyfying v:collisionbullets like so:
Code: Select all
function Enemy1:collisionbullets(b, i, g)
if self.y + self.height >= b.y and self.y <= b.y + b.height
and self.x <= b.x + b.width and self.x + self.width >= b.x then
table.remove(enemies, i)
table.remove(bullets, g)
for i,v in ipairs(enemies) do
if i == 1 then
v.y = v.y+x --x is the shifted value--
end
end
end
end
I'm not sure what this is and I do realize this is a fairly long post, but if you would like to help, I'll appreciate all of it, maybe the problem is in the library, or maybe it's in me, also I hope I provided all the needed information