ThePatrickP

I was just wondering has this is done usally (collision detection with the 3d game level). Would I detect collision with the mesh or make some file which contains boundingBox positions or would I make boundingBoxes in the mesh file Thanks in advance.

Re: XNA Game Studio Express 3d collision detecting with level

magicalclick

I have no experience, but personally I think it should be separated. Because then, you can reuse it to the simular model, like character model. And your design will be more flexible for different needs.



Re: XNA Game Studio Express 3d collision detecting with level

grifft

If you're creating a Model instance containing the Mesh, the Model automatically creates a BoundingSphere instance that can handle basic collision detection through the Intersects method.

The base BoundingSphere isn't sufficient for most rectangular/oblong models as the sphere's radius would be half the longest side (which is the smallest size the sphere can be to contain all mesh points). You have to create smaller spheres along the mesh bones (data loaded in with the mesh) to get accurate colission detection on those types. BoundingBoxes work, but only if the object doesn't need to be rotated to any degree. An excellent tutorial on this topic (with source code) is located at http://sharky.bluecog.co.nz/ page_id=113.

BTW - keep the Boundary info with the mesh in a class for the gameobject that you're working with. Spearate files would be twice the troubleshooting, and require duplicated scale, rotation, and transformation code for every pass (60/sec). Then, if you need more than one "car", you can create a new instance of the mesh and it's behaviors.

Good luck.






Re: XNA Game Studio Express 3d collision detecting with level

areia

Collision detection is regarded one of the most complex problems in games programming. Depending on the exact "arrangment" that makes your game work, a specific combination of methods usually is the ideal. I don't know how experienced you are in maths but that's all about it. The more maths you understand, the more reading material will be readable to you if you search around.

If on the other hand maths is not your favourite subject, the almost build-in XNA's bounding box check that was mentioned above will work for many cases. In this case you just have to compare two boxes to determine if one is inside the other. You can also use the bounding spheres of two models for a fast pre-calculation, then proceed to a more detailed if the two spheres collide. Bounding box and bounding sphere collision detection is so common that just searching over a search engine on the net, will give you tons of examples. Of course a book is almost always better than online.

A thing to mind is that you should also investigate some methods to reduce the possible collision checks. Dividing your world in quads (cubes if you like) is a very simple and easy one. You start by diving the complete world in four, then each forth in four and so on, till you reach a size that won't slow down your game. Then when an object is created in the world, you assign it in a quad. Now depending on which quad an object is in, you only need to check in this and its surrounding quads, for that object.

My suggestion Start a non-XNA, non-DirectX command line program in C# and write very fast/hack code, producing many "supposed game objects" in random/various positions. Then slowly add the features you want for this specific problem (like the bounding boxes, spheres, quads etc...) but avoid using 3D graphics. That will help you concentrate on the problem. Use the Console class to output your debug information. Once you make it work, it will be piece of cake to write the proper and working code in your actual game application.





Re: XNA Game Studio Express 3d collision detecting with level

ThePatrickP

I wasn't really asking about normal collision detection. I wanted to know how the collision with the game level (in a first person shooter) is handled. because there you can't just use spheres or bounding boxes.