简体   繁体   中英

Checking a rectangle collision with a circle

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM