0
\$\begingroup\$

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();

enter image description here

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

Thank's a lot guy

\$\endgroup\$
2
\$\begingroup\$

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)

edit: after some more info...

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)

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ 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" \$\endgroup\$ – Mehdi Bugnard Apr 17 '14 at 12:44
  • \$\begingroup\$ @MehdiBugnard see my edit, you can use 3 lines that extend from the centers of the faces to detect your collisions \$\endgroup\$ – ratchet freak Apr 17 '14 at 12:50
  • \$\begingroup\$ Thank's a looot ! For remember me this easy way ^^ . I update the answer \$\endgroup\$ – Mehdi Bugnard Apr 17 '14 at 13:40
  • \$\begingroup\$ @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. \$\endgroup\$ – OriginalDaemon Apr 17 '14 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.