This formula only works between circles and their x and y locations are measured from the center of them. I made this into my own function for ease of use. r is Radius
if ((r1+r2)*(r1+r2) > (x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)) {
// HIT!
}
Does anyone know how performance intensive that is? It seems like running hittest compared against 20 or so tiny rectangles for each object would be exponentially bad. Like you could have 3 or 4 objects before crashing hardcore. Anyone actually use this method?
You’d want to hitTest the larger shape itself before committing to checking all the little ones, but if you do that you can get away with a few hundred hitTests each frame pretty easily without running into any slowdown. Though it depends a lot on the frame rate and computer of course.