Page 1 of 1

how to create collision between two entities.

Posted: Mon Aug 10, 2015 1:14 am
by eqnox
I know this has been asked a million times but all the treads I look at seem to not work. I have a player and an enemy and I want them to collide. At the moment they are both just rectangles.

Re: how to create collision between two entities.

Posted: Mon Aug 10, 2015 12:39 pm
by TomBebbington
https://github.com/kikito/bump.lua is probably what you're looking for. It's really easy to set up, has a great tutorial and is incredibly fast.

Re: how to create collision between two entities.

Posted: Mon Aug 10, 2015 1:36 pm
by sefan
Here is a simple collision detection function:

Code: Select all

-- Collision detection function.
-- Returns true if two boxes overlap, false if they don't
-- x1,y1 are the left-top coords of the first box, while w1,h1 are its width and height
-- x2,y2,w2 & h2 are the same, but for the second box
function CheckCollision(x1,y1,w1,h1, x2,y2,w2,h2)
  return x1 < x2+w2 and
         x2 < x1+w1 and
         y1 < y2+h2 and
         y2 < y1+h1
end
Link to Love2D wiki: http://love2d.org/wiki/BoundingBox.lua