how to create collision between two entities.

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
eqnox
Prole
Posts: 44
Joined: Fri Jul 31, 2015 2:36 pm

how to create collision between two entities.

Post 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.
TomBebbington
Prole
Posts: 2
Joined: Mon Aug 10, 2015 12:36 pm

Re: how to create collision between two entities.

Post 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.
User avatar
sefan
Prole
Posts: 23
Joined: Fri Jul 31, 2015 7:03 am
Contact:

Re: how to create collision between two entities.

Post 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
Sefan.se GitHub.com Itch.io
Looking for help on graphics/music/sound effects. PM me if interested.
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests