The Collision structure that gets passed to OnCollisionEnter, etc, has an array of ContactPoints that report the points where the incoming collider made contact. Unfortunately, the contact point only gives the position in space and not the mesh face. However, if the object is a simple cube then you may be able to figure out the face with a bit of vector arithmetic. You can use transform.InverseTransformPoint to get the location of the collision in the cube’s local space. From that, you could see which axis of the local point has the greatest absolute value and determine the face from that (eg, if the positive X coordinate is greater than the other two then the hit occurred on the right hand face, etc). You can also use Vector3.Distance to measure the distance from the contact point to the centre of the face.
Of course, if you start using a mesh that is more detailed than a cube then things could get a bit more complicated
for determining the up-face of a die, i think it would be much easier to measure the angular velocity to see if it has finished rolling yet, and then just check its resting orientation to figure out which face is up.
Wow! Thanks andeeeee and Cpt Chuckles,
Both those answers are great. I did not know about transform.InverseTransformPoint and never thought of using the angular velocity.
Thanks, I will try each of those answers.