Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

DevLiquidKnight

How do you do Collison detection in a cricle rather then rectangle

This topic is 5884 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i was wondering how do you test for collision if your object is a circle and you dont want to test for a rectangle but rather a circle ? I never have done anything with circles or polygons so could someone show an example?

Share this post


Link to post
Share on other sites
Advertisement
Circle collision is much easier than rectangle collision. The test for this looks like this:

If SQRT((Circle1.X, Circle1.Y) ^ 2 + (Circle2.X, Circle2.Y)^ 2) <= Circle1.Radius + Circle2.Radius Then
''Collision Detected
Else
''No Collision
End If

That''s how simple it is. I basically test the distance between both center points of the circles, Then it checks if that distance is less then the combined radius of the two circles. If the distance is les then there has been a collision.

That''s it

Horny Farmer (Jolly Rancher)

Share this post


Link to post
Share on other sites
something to note here is that the sqrt is slow.

im not sure, but would this be faster?

if (a^2+b^2)<(r1+r2)^2 then {} else {}

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!