Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: checking circular collisions  (Read 1424 times)

0 Members and 1 Guest are viewing this topic.

dotty

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
checking circular collisions
« 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
checking circular collisions
« Reply #1 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.
Laurent Gomila - SFML developer

Contadotempo

  • Full Member
  • ***
  • Posts: 167
  • Firelink Shrine
    • View Profile
checking circular collisions
« Reply #2 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

 

anything