Saturday, January 28, 2012

Collision detection against rays to circles

After toiling for a little while, I came up with a pretty nifty method for detecting when our beams hit against a circle hit box. The method involved solving the y = mx + b equation of the beam, and then taking the normal equation of that that passes through the center of the circle. Then through some algebra manipulation you solve for when the two are equal, which then lets you easily solve for y. Once you have this, you essentially know how close the beam is to the circle, make a simple check against the length of the radius, and in 6 lines of code you know if you have a collision.

2 comments: