SFML community forums

Help => Graphics => Topic started by: dotty on February 15, 2012, 08:19:11 pm

Title: checking circular collisions
Post by: dotty on February 15, 2012, 08:19:11 pm
Hello, I know I can use IntRect() which have some decent methods for working out collisions between them. How would I go about doing this with circular shapes?
Title: checking circular collisions
Post by: Laurent on February 15, 2012, 08:45:56 pm
Collision between circles is the simplest thing that you can do. Check if the distance between the centers is less than the sum of both radiuses, and that's it.
Title: checking circular collisions
Post by: Contadotempo on February 15, 2012, 10:20:20 pm
Something like:
Code: [Select]
if((x1 - x2)^2 + (y1 - y2)^2 < (radius1 + radius2)^2)
     youhavecollision();


Where x and y  is the position of the center of each circle.
That's pseudo-code of course but I think you can get the idea.  :P