I'm new to this forum and I recently picked up Lua and Love2D. After a few tutorials, I started to feel confident and make my very first game.
Currently I have been making a AABB collision and response program that will correct the player depending on the moving object direction.
The problem however is that as seen on the attachment. The blue box (moving object) is attempting to collide with the static black box. Because it is moving diagonally, it sets the variables dirX and dirY to be true thus sending the blue box to the orange position rather than the desired yellow position. Any ideas how to fix this?
Code: Select all
function collisions:update() -- checks for every object on scene for i = 1,#colliders do --checks for every tile (solid) on scene for j = 1,#platforms do object = colliders[i] platform = platforms[j] collision = ( object.x + object.width > platform.x and object.x < platform.x + platform.width and object.y + object.height > platform.y and object.y < platform.y + platform.height) if collision == true then print ("hey") if object.dirX > 0 then object.x = platform.x - object.width -1 print("r") end if object.dirX < 0 then object.x = platform.x + platform.width +1 print ("l") end if object.dirY < 0 then object.y = platform.y + platform.height +1 print ("u") end if object.dirY > 0 then object.y = platform.y - object.height -1 print ("d") end end --gravity end end end