Tearing my hair out over collision
Posted: Tue Jun 21, 2011 12:54 am
I'm trying to collide my character with a table of boxes. I'm using the box collision shown in the wiki. I can get it to work without the else statement. But when I add it, collision doesn't happen.
Works but won't unCollide
Doesn't work at all
Works but won't unCollide
Code: Select all
for i = 1, table.getn(level.boxes) do
if CheckCollision(player.pos.x, player.pos.y, player.image:getWidth(), player.image:getHeight(),
level.boxes[i].x, level.boxes[i].y,level.boxes[i].width, level.boxes[i].height)
then
player.onGround = true
end
end
Code: Select all
for i = 1, table.getn(level.boxes) do
if CheckCollision(player.pos.x, player.pos.y, player.image:getWidth(), player.image:getHeight(),
level.boxes[i].x, level.boxes[i].y,level.boxes[i].width, level.boxes[i].height)
then
player.onGround = true
else
player.onGround = false
end
end