Jump to content
  • Advertisement


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

G a m e D e v

collision detection with circle

This topic is 6199 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

Original post by G a m e D e v
How do I detect a collision with two circles? How do I tell what angle they hit?

If the circles have radiuses r1 and r2, then they hit when their centres are a distance (r1 + r2) apart. You can work out the distance using Pythagoras''s theorem, i.e.

dist = sqrt((x1 - x2)2 + (y1 - y2)2)

where they are at (x1, y1) and (x2, y2)

And they are overlapping, i.e. they have hit, when

dist < r1 + r2

The vector

(x1 - x2)
(y1 - y2)

gives the direction between the circles. There are various angles you can measure, e.g. the angle between this direction and the x axis is given by

angle = arctan ((y1 - y2) / (x1 - x2))

Alternately you can just use the vector as this gives you the direction in a format that can be easily used elsewhere. E.g .the force between the circles if they bounce apart will be along this direction.

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!