Page 1 of 1

Help with basic collision detection

Posted: Wed Feb 20, 2013 5:16 pm
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?

Re: Help with basic collision detection

Posted: Wed Feb 20, 2013 7:04 pm
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.