How can I determine which side is facing upwards?

Since forever I’ve been wanting to create a board game type of style (which’ll include a dice), but I always get stuck on one part.

How can I determine which side of the dice is facing up, and how can I get the value of the dice?

I’ve tried to look at some other forums but it still leaves me confused.

image

If I’m not wrong you should be able to know which side is facing up by using some kind of command which I don’t remember, maybe something like

part.Top?

Not sure tho, and also, you could raycast from each side, if one side is touching the floor, get the number that’s there, and form there you will know which number is where

This isn’t a valid property.


As for the question:

You can get the topmost face by comparing the dot products of all 6 faces to the upwards vector (which is Vector3.new(0, 1, 0)). The face with the highest dot product is the face that’s facing up:

-->> in this example, there are only two faces being compared, you would have to compare all 6
local upwardVector = Vector3.new(0, 1, 0)

local rightVector = Part.RightVector --> the top face relative to the dice
local leftVector = -Part.RightVector --> the bottom face relative to the dice

local rightVectorDot = rightVector:Dot(upwardVector)
local leftVectorDot = leftVector:Dot(upwardVector)

if rightVectorDot > leftVectorDot then
    print("right vector is facing up more than left vector")
else
    print("down vector is facing up more than up vector")
end
2 Likes