Sign in to follow this  
zer0sum

Circular Hit Boxes Math Question

Recommended Posts

zer0sum    100
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?

Share this post


Link to post
Share on other sites
zer0sum    100
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.

Share this post


Link to post
Share on other sites
jyk    2094
'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!]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this