I am making a little voxel clone before the main work on NYNS. I started in the playground, but I’m moving it to the editor later. Right now the system in which I detect what side of a cube to place a block on is kinda primitive. It doesn’t work 100% of the time, but it doesn’t misplace a block.
Playground here: https://playground.babylonjs.com/#D1Z1VL#1
At lines 67 - 91 is where it takes place. The variables xx, xxx, yy, yyy, zz, zzz are what control where to place the blocks. lines 85, 86, and 87 are the side detection. They compare the distance from the picked mesh (for the original cube 0,0,0) with the picked point. It looks for which variable (in this case xx, yy, and zz) is equal to 0.5. Since the cube is 1 x 1 x 1, the distance from the center to a side should be 0.5. Sometimes it is 0.49999999999999999 and can be seen if you add a console.log.
I’m wondering if there is any better way to the the side detection.
Thanks for any help,