0

I have two objects, a rectangle object and then a circular shaped object. At the moment i am using two rectangles to detect the collision of these objects, and although it is working the collision detectment is not accurate enough because using a rectangle means the collision is detected before the circle has actually been hit.

My question is what method could i use in order to detect the collision with the circle so that the collision is only detected when the rectangle actually intersects the circular object?

dcastro
  • 66,540
  • 21
  • 145
  • 155
Charlie Stuart
  • 272
  • 2
  • 5
  • 19
  • 1
    Possible duplicate: http://stackoverflow.com/questions/401847/circle-rectangle-collision-detection-intersection. That question is not C#/xna specific, but contains several useful answers. – Paolo Tedesco Mar 06 '14 at 11:35
  • he's asking for methods to use – Leggy7 Mar 06 '14 at 11:53

1 Answers1

0

If you're using XNA you could create BoundingSphere for the circle and BoundingBox for the rectangle, then call sphere.Intersects(box) to check if they collide.

See that the BoundingSphere and the BoundingBox both have constructors that could fit your 2d needs

Leggy7
  • 483
  • 9
  • 23