Circular Hit Boxes Math Question

Started by
1 comment, last by Zakwayda 13 years, 12 months ago
Say I have two objects and I want to create circular hitboxes. I have the center of each point and a radius: point1 (x1 ,y1, r1); point2 (x2, y2, r2). I am using a 2D coordinate system where upper left is 0,0, x increases to the right, y increases to the bottom. How do I test for collision between these circles?
Advertisement
Upon further reflection, this has a simple answer. Test the distances between the centers! Duh. If at any point the distance of between (x1, y1) and (x2, y2) is <= r1+r2, then I've got a collision.

Duh.

Sorry.
'Circular hitboxes', huh? Hehe... :-)

Anyway, testing for intersection between two circles is super-easy. If the distance between the centers of the circles is less than the sum of their radii, there is an intersection. (In practice, squared distances are usually compared for the sake of efficiency.)

You can also easily derive other collision data (minimum translational vector, collision point and normal, etc.) from this info if needed.

The continuous version of the test is also pretty straightforward (it basically reduces to a segment-circle intersection test).

[Oops, too late!]

This topic is closed to new replies.

Advertisement