hitTest for Circles

Subscribe to hitTest for Circles 7 posts

Sign in to reply


 
avatar for yaim0310 yaim0310 6 posts
Flag Post

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!
}
 
avatar for Cloud_9ine Cloud_9ine 2434 posts
Flag Post

i found a perfect tutorial for strange shapes hittest

http://www.kirupa.com/developer/actionscript/advanced_collision.htm

 
avatar for fucrate fucrate 61 posts
Flag Post

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?

 
avatar for Moonkey Moonkey 1007 posts
Flag Post

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.

 
avatar for fucrate fucrate 61 posts
Flag Post

ooh, yeah. multi-level detection tactics. good stuff.

 
avatar for IndieFlashArcade IndieFlashAr... 433 posts
Flag Post

It seems like running hittest compared against 20 or so tiny rectangles for each object …

I don’t get what you’re saying, it seems like you would only need to do one hit test for each circle.

 
avatar for yaim0310 yaim0310 6 posts
Flag Post

to Indie: They are talking about the hittest from they link provided by Cloud

Sign in to reply