Need help understanding XNA 4.0 BoundingBox vs BoundingSphere Intersection

Posted by nerdherd on Game Development See other posts from Game Development or by nerdherd
Published on 2012-06-10T22:38:35Z Indexed on 2012/06/10 22:48 UTC
Read the original article Hit count: 387

Filed under:
|
|

I am new to both game programming and XNA, so I apologize if I'm missing a simple concept or something. I have created a simple 3D game with a player and a crate and I'm working on getting my collision detection working properly. Right now I am using a BoundingSphere for my player, and a BoundingBox for the crate. For some reason, XNA only detects a collision when my player's sphere touches the front face of the crate.

I'm rendering all the BoundingSpheres and BoundingBoxes as wire frames so I can see what's going on, and everything visually appears to be correct, but I can't figure out this behavior.

I have tried these checks:

playerSphere.Intersects(crate.getBoundingBox())

playerSphere.Contains(crate.getBoundingBox(), ContainmentType.Intersects)

playerSphere.Contains(crate.getBoundingBox()) != ContainmentType.Disjoint

But they all seem to produce the same behavior (in other words, they are only true when I hit the front face of the crate). The interesting thing is that when I use a BoundingSphere for my crate the collision is detected as I would expect, but of course this makes the edges less accurate.

Any thoughts or ideas? Have I missed something about how BoundingSpheres and BoundingBoxes compute their intersections? I'd be happy to post more code or screenshots to clarify if needed. Thanks!

© Game Development or respective owner

Related posts about XNA

Related posts about collision-detection