- Home /
3D Cube Face Detection
Hi,
I have a set of 3D cubes placed evenly next to each other with different coloured faces, but I need to detect which face is currently showing towards the user. I have managed to use the "Forward" + "Up" calculations to detect when the cubes are all facing in the extact orientation, however I very urgently need a way to do the same thing with only the the face colour showing the user being the same! I.E. All cube faces have a different colour, as we all know the cube can show the same colour to the user but be of different orientations... This is what I need to do, but currently my game code only allows the "exact" cube orientation to react. I need to find a way to detect for example, when all cubes show the colour "Red" to the user - regardless of the orientation of the cubes. Could anyone please suggest anything or maybe something I have missed with using the "Forward" + "Up" detection method ???? Any help would be greatly appraciated.
Regards, Jimmy.
Answer by Drakestar · May 16, 2012 at 02:24 PM
You figure out how much a vector is facing another vector by calculating the dot product between the two. In this case, you'd use the camera's facing direction and the normal of the side of the cube that is facing you. There are lots of information and examples around if you look for "Unity Vector3.Dot"
An even easier solution, though, would be to compose the cube out of six individual planes (or parenting them to each side of the cube) - that way, you don't have to bother with extracting the individual face normals from the cube (or trying to compute it based on the cube's rotation).