Skip to content

Comment on How I implemented 2D collision detection in Pistol Slut

Comments

You might want to google for "separating axis test", it is a very simple technique that allows you to detect collisions between any two convex polygons. It can also handle continous collisions detection for translation (your moving grenades) very easily.

In your axis-aligned case, you would project the objects you test on both axes (x and y). If the do not overlap on any one of the axes, they do not collide, otherwise they do. To handle movement you project each objects movement vector on the axes as well and add that to the objects projected interval.

To find out which grid squares that are covered by a polygon amounts to resterization, which you can find many tutorials for with google.

Axis aligned boxes are trivial to rasterize. For more complex shapes you write a rasterizer for triangles and handle arbitrary polygons by breaking them up into triangles (google "ear clipping").

Great. I'll check out the separating axis test, too - thanks. Incidentally, I believe The Render Engine, the framework I used, has just introduced support for this technique.

You can also rotate the axes to align with one object's motion. Then the 'axis test' reduces to one axis, and collision is a line-segment test.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.