Search code examples
xcodecocos2d-iphonecollision-detectionspritegeometry

cocos2d : detect collision between two circles


so I have two sprites that are circles. I would like to know when they collide. My problem is that they collide like they were rectangles.I don't wanna use box2d, just with cocos2d is there a way to detect collision between two circles ?


Solution

  • If you have (or can get) the radius of the circle, then you can compare the sum of the radii to the center-to-center distance.

    A common trick in some computational fields is to work with distance-squared (so you don't have to take the computational hit of the square root). In this case you would compare d-squared with (r1 + r2) squared.