Working on a mining / building game.
I am in the placing blocks phase of development.
I cast a ray, when it hits a block, I get the empty space beside that face that was hit.
Even though, I get the ‘space’ beside blocks, rotation can sometimes depend on which ‘face’ of the adjacent blocks was hit. So its important that I know which face was hit.
However, some faces might be invalid to place upon (just for example, we will pretend the grass block in the image is not a valid face)
So, when I go to place a block in the space (steps in this case)…
The steps need to know how to rotate, based on the block they are being connected to.
However, the ray is being cast and hitting the invalid grass block.
There are, though, plenty of valid blocks around this empty space, that the stairs could be
considered ‘attached to’ or ‘placed upon’, such as the wooden, dirt and plaster walls around it.
So my question, and problem is. How do I select of these 3 alternative faces, which one is more valid (in my case, which one is more facing the camera head on) to be used as the alternate (attachment) block.
Just thinking about this, I feel the simplest way would be to put an imaginary block inside the empty space. Then see which face on that block is closest to the camera (from the center of each face to the camera) Then take the closest face, in the case of the picture, it would be the yellow, then get the neighboring block (cell) opposite that face, and then use the corresponding face of that neighbor block as a connection point.
I am just lacking on some math to do this efficiently. Or perhaps there is a better way of doing this. Without testing it, I don’t know if this will actually give me the most parallel face in regards to the camera’s view frame or not.
Any help is appreciated, thanks.



