I'm currently working on an Infinite Runner 2D game. Actually I've great problem with Love2D CheckCollision function. Let me explain :
My player has different states like isStanding, isFalling, each steps defines a different animations for the player and his velocity.
In my Update function I want to verify if my player isColliding with some tile. If that's the case, I want to change the state of my player to isStanding. This part is fine, everything works.
Also in my Update function, I want to detect when my player is not on a tile and then change his state to isFalling, but it's not works.
After few hours of tests and debugs, I have understand what is the problem but I don't now how to solve it. Here's my code for what I've explain above :
Code: Select all
for n=1, #listTiles do local tile = listTiles[n] -- Updating tiles speed --tile.vx = tile.vx + tile.speed * dt -- Move --tile.x = tile.x - tile.vx * dt -- if tile is out of screen, delete if(tile.x + tile.pic:getWidth() < 0) then tile.toRemove = true end SetTileCollideBoxes(tile) UpdateTileBox(tile) for i=1, #pPlayer.collideBox[pPlayer.currentAnimation] do local collideBox = pPlayer.collideBox[pPlayer.currentAnimation][i] -- Fixing player on the top of platform when he's falling collide = CheckCollision(pPlayer.x + collideBox.x, pPlayer.y + collideBox.y, collideBox.w, collideBox.h, tile.collideBox.x, tile.collideBox.y, tile.collideBox.w, tile.collideBox.h) if (collide) then pPlayer.y = tile.collideBox.y - collideBox.h + 10 pPlayer.isFalling = false else pPlayer.isFalling = true end end end