Skip to content Skip to sidebar Skip to footer

What's The Best Way To Do Collision Detection?

I have a need to define a polygon that would be the 'legal' area, and allow a user to move a rectangle around within that polygon, preventing them from moving the rectangle anywher

Solution 1:

Metanet's excellent collision detection tutorial has a good section on how to do swept collision with axis-aligned bounding boxes (AABB) and arbitrary "walls."

If your polygon is concave, you'll probably find it easiest to first decompose it into multiple convex polygons, which will simplify the available collision detection algorithms.

Solution 2:

If you only looking to check the corners of the rectangle, you can do a "inside" test for each of them. http://en.wikipedia.org/wiki/Point_in_polygon

And if you also want to make sure that no pointy part of the polygon "punctures" your rectangle you could do a test for each of the 4 lines in the rectangle against all the lines in the polygon to see if they are intersecting. http://en.wikipedia.org/wiki/Line-line_intersection

Post a Comment for "What's The Best Way To Do Collision Detection?"