[solved]Collision response: the right direction
Posted: Tue Aug 14, 2018 12:33 pm
Hey,
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?
Edit 10/12/2018:
I simply tagged objects if they are in the x axis of moving object or y axis of moving object
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.
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
Edit 10/12/2018:
I simply tagged objects if they are in the x axis of moving object or y axis of moving object