Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Basic 2d collision detection

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?

like image 446
Bain Markev Avatar asked Oct 03 '10 20:10

Bain Markev


People also ask

What is collision 2d?

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).

How do you do collision detection?

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.


1 Answers

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.

like image 78
Siyu Avatar answered Oct 21 '22 09:10

Siyu