Discord
Login
Community
DARK THEME

AABB issues

My AABB collision function doesn't work for negative coordinates for some reason. It does work with normal coordinates like 100, 100 but not with -100, 100. My whole game is literally built on a place been on negative coordinates so... I'm cooked:(

Can you send the function code?

Here's an example of AABB collision detection you can use in your game. To use it, use: if checkCollision(obj1,player) then//do somethink

Note that your objects must have a defined width and height for the function to use them in the calculation.

checkCollision = function(r1, r2)
  return r1.x - r1.width/2 < r2.x + r2.width/2 and
         r1.x + r1.width/2 > r2.x - r2.width/2 and
         r1.y - r1.height/2 < r2.y + r2.height/2 and
         r1.y + r1.height/2 > r2.y - r2.height/2
end

Thank you so much :)

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community