Help with basic collision detection

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
noatom
Prole
Posts: 10
Joined: Sun Feb 17, 2013 9:51 pm

Help with basic collision detection

Post by noatom »

So if I have 2 of these:
Image

What shape should I use for collision detection? I don't want a rectangle because it's way too restrictive...

Also,is there a tutorial on how to implement that shape?
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Help with basic collision detection

Post by Roland_Yonaba »

You can use a simple rectangle.
If this isn't precise enough, you can define a more complex polygon.
A simple table with a set of ordered x,y pairs, so that the polygon would be counterclock-wise, and convex.

Code: Select all

Polygon = {
  {x =..., y = ...},
  {x =..., y = ...},
  {x =..., y = ...},
  ...
}
Later on, for convenience, you can wrap it as a class, and implements methods for generating new polygons, check for intersection, etc.
Well, problem is you will have to handle all by yourself collision with others shapes (like circles, rectangles, lines, points). That will require some maths, but nothing complicated.
There's a handy library that deals with that kind of stuff very well, actually. Look for HardonCollider.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 7 guests