Answers for "Dice Value"
http://answers.unity.com/questions/636775/dice-value.html
The latest answers for the question "Dice Value"Answer by robertbu
http://answers.unity.com/answers/636816/view.html
This code is using the dot product in a very specific way. What they are doing only works if all the vectors involved are normalized (i.e. of unit length). All the ones they are use are normalized. When two normalized vectors are pointing in the same direction, their dot product value will be 1.0 (give or take a bit due to floating point imprecision). If two vectors are pointing in opposite directions, then dot product will be -1.
The other thing going on here is the value of each side of the cube. Their cube has the following values:
+ front - 7
+ back - 4
+ right - 8
+ left - 3
+ top - 5
+ bottom - 2
So take a look at lines 9 - 11. First the forward vector is compared with world up. If they are the same (i.e. dotFwd > 0.99f), then you know the forward side is facing up. If the value is near -1, then you know the back side is facing up.
Lines 13-15 text left/right.
Lines 17-19 test top bottom.
In the unlikely event the cube is on the edge (i.e. it got hung up on something), the function returns 0.Tue, 11 Feb 2014 06:27:20 GMTrobertbu