# How to retrieve a cube collision by faces

I work for a while on a minecraft game (voxel). I am front a problem for a long time about the collision detection. I want recover the cubes collision from my highlighted black's cube like on the picture , but only on the sides. And not on the edges ! Actually i got all cubes in red and green when i check with the boundingBox method. Actually i use the method with the class "BoundingBox" to check for collisions. Can anyone help me or direct me on the best way for retrive the right cube ?

Code example with the boundingBox methode for check the collision

List<Node> nodeParent = regions[modelSelected.regionIndex].Nodes[modelSelected.Id].Where(m => modelSelected.BoundingBox.Intersects(m.boundingBox)).ToList();


i want to get only the green cube and not the red .. From the black cube in the middle

Thank's a lot guy

you are in a voxel engine which means that each box should have a discrete x, y and z coordinate thus:

if you have a box at index (x, y, z) then you can get all neighbouring boxes by getting the boxes at index (x, y +/- 1, z), (x +/- 1, y, z) and (x, y, z +/- 1)

just detect the collisions for a line between the center of the current cube and the center of the potential neighbouring cube,

thus instead of intersecting with the bounding box of the cube you intersect with 3 lines strechting from (x, y-1, z) to (x, y+1, z) and (x-1, y, z) to (x+1, y, z) and (x, y, z-1) to (x, y, z+1)

• Unfortunately, the problem is that my voxel world is divided into "Octree" with several node cubes. Cubes around my black cube will not necessarily unique cubes but can be node cubes. That's why I want to work with the class "BoundingBox" Apr 17 '14 at 12:44
• @MehdiBugnard see my edit, you can use 3 lines that extend from the centers of the faces to detect your collisions Apr 17 '14 at 12:50
• Thank's a looot ! For remember me this easy way ^^ . I update the answer Apr 17 '14 at 13:40
• @Mehdi Bugnard - if the octree is being restrictive in this case, and results in noticeable overhead, you could consider shadowing it with another structure (replace it with). For example a 3D array of the tree leaves or a spacial hashing system. Apr 17 '14 at 15:13