Where can I go to read more about basic 2d collision detection for games or just applications that have some interactivity?
Edit: How about javascript for Canvas games?
If two objects make a head on collision, they can bounce and move along the same direction they approached from (i.e. only a single dimension). However, if two objects make a glancing collision, they'll move off in two dimensions after the collision (like a glancing collision between two billiard balls).
If both the horizontal and vertical edges overlap we have a collision. We check if the right side of the first object is greater than the left side of the second object and if the second object's right side is greater than the first object's left side; similarly for the vertical axis.
The most important theorem to know is the Separating Axis Theorem (SAT). Basicly, it allows you to detect collision between two convex polygons. A good reading material is here.
If your game only concerns with convex shapes, then sat.js
is a decent choice.
However, if you need to work with concave shapes, you need to other algorithms. You can decompose a concave shape into several convex shapes, poly-decomp.js
can do it for you.
This paper is very interesting if you want to dive deeper.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With