vichnaiev

This may sound really stupid, but I'm new to this stuff, so if anyone could help ...

I can't get collisions on bounding boxes. I tried first with moving objects, after no sucess on that I even tried to create two boxes on top of each other and call the Intersects() method, it will still return false. This is how my code looks like:

BoundingBox bbtest = new BoundingBox(new Vector3(0.0f, 1.0f,0.0f), new Vector3(1.0f, 0.0f, 0.0f));
BoundingBox bbtest2 = new BoundingBox(new Vector3(0.0f, 1.0f, 0.0f), new Vector3(1.0f, 0.0f, 0.0f));
bool test3 = bbtest.Intersects(bbtest2);

I gotta be doing something wrong here, it can't return false.



Re: XNA Game Studio Express Problems with bounding boxes collision

Fluxtah

Try setting your min/max vectors in another manner

BoundingBox bbtest = new BoundingBox(new Vector3(-1.0f, -1.0f,0.0f), new Vector3(1.0f, 1.0f, 0.0f));
BoundingBox bbtest2 = new BoundingBox(new Vector3(-1.0f, -1.0f, 0.0f), new Vector3(1.0f, 1.0f, 0.0f));

That should do the trick.





Re: XNA Game Studio Express Problems with bounding boxes collision

vichnaiev

That didn't work either. =/ Screenshot of the debugging below.

http://img178.imageshack.us/img178/5057/boundedboxwn5.jpg

(couldn't display the image directly on this page, [img] tags don't seem to work.





Re: XNA Game Studio Express Problems with bounding boxes collision

Fluxtah

In that image the bounding boxes min and max are not as the code I pasted above which is strange.

should be

min: -1,-1,0
max 1,1,0





Re: XNA Game Studio Express Problems with bounding boxes collision

BikeDude

Fluxtah, surely those coordinates describes the same rectangle/square (btw: can a square be described as a flat cube )

Does it make any difference in case the squares are inflated a bit





Re: XNA Game Studio Express Problems with bounding boxes collision

Fluxtah

It is the same but if you imagine the boxes origin is in the center then the minimum X and Y would be -1, -1 and the maximum would be 1,1 at least this is how BoundingBox has worked for me, and I have done the same thing as above and got the same issues, only when I did it the way I described I resolved them.

You could be right about the flat box, maybe put some z in there also





Re: XNA Game Studio Express Problems with bounding boxes collision

Jon Watte

Those boxes are both empty (zero volume). An empty box cannot intersect anything.





Re: XNA Game Studio Express Problems with bounding boxes collision

Rick Mogstad

Your bounding box definitions define the bottom left corner, followed by the top right corner. I think that may be part of your problem. To define the same box, you would want to use


BoundingBox bbtest1 = new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(1f, 1f, 0f));
BoundingBox bbtest2 = new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(1f, 1f, 0f));
System.Diagnostics.Debug.Print(bbtest1.Intersects(bbtest2).ToString());

That puts the top left corner at 0,0, and the bottom right at 1,1 (as I think you intended). In yours, you are defining the first corner at 0,1, and the 2nd at 1,0. Same rectangle, but defined the way I think the framework expects it.




Re: XNA Game Studio Express Problems with bounding boxes collision

vichnaiev

Hey guys, thanks so much for all the posts and your help. A few things that might help people how see this post:

1 - the depth is not a problem. it does not need to be a cube, it can be a simple square with no z difference between min and max.

2 - the documentation seems to be incorrect or I am looking at it from a negative z (not sure what the default is). =/

"the minimum point is the lower left corner of the back face of the BoundingBox when looking at it from the positive z direction"

"the maximum point is the upper right corner of the front face of the BoundingBox when looking at it from the positive z direction."

So, this is it. I was inserting wrong coordinates, that's why I couldn't detect collisions. Thanks again for stopping by and helping.