# Ripple Character Collision – Part 2: Circle-Line Collision

posted in: Senior Team | 0

Greetings! On the previous post, I talk about the various stages of collision detection we went through to get to a version that will work well for our game. For this post, I will talk about the Circle-Line Collision that we used in out game. We chose the circle line collision approach because the characters are circular shapes, and the ripples, thanks to Vectrocity, are made up of line segments. Using a bit of vector math we were able to get reliable collisions that worked with different ripple shapes.

There are four components that we will need for the calculation and three checks we make for collision. Points A and B will give us our line segment AB. We will then also need the center point of the circle, C, and the radius, R. To start off we will want to calculate vector CA, or C – A.

Once we have CA, we will project it onto BA, which will give us vector DA.

From here we calculate vector DC.

At this point we have enough information to start performing our checks to see if there is actually a collision.

First Check:

Check to make sure that the magnitude of DA is less than or equal two the magnitude of BA.
||DA|| <= ||BA||

Second Check:

Check if DA and BA are pointed in the same direction.

Third Check:
Check if the magnitude of DC is less than or equal to the radius.

||DC|| <= R

If all these checks are true, then congratulations, you have some basic circle-line collision checking.

The first and second checks are to make sure that the center of the circle is located between points A and B. The third check determines if the size of the circle crosses the line BA.

Since switching over to this collision detection we have not run into any frame rate drops do to collision, and testers have not had any unfair tests.

-Jack Storm