I made a dice that is rolled by setting the AssemblyAngularVelocity, then after some time, I set it to 0, 0, 0, anchored the dice, and then calculated which side the dice rolled on. It’s calculated through its orientation plus the perfect xyz values that can give you that dice number, but there are some flaws with this.
- The orientation can sometimes be values such as
-40, 120, -56which cannot be calculated and just causes the script to stop moving on due to me looking at the perfect orientations that the dice need to be at. - In certain cases when the dice is on three it will be calculated as being on two due to the orientation not being perfectly
0, 0, -90.
So how can I find the correct dice number by calculating its orientation?
Script
local diceRotationTable = { -- A table that contains the values for the possible x, y, and/or z rotations of the dice depending on where the dice lands
[1] = Vector3.new(0, 0, 0),
[2] = Vector3.new(90, 0, 0),
[3] = Vector3.new(0, 0, -90),
[4] = Vector3.new(0, 0, 90),
[5] = Vector3.new(-90, 0, 0),
[6] = Vector3.new(0, 180, 180)
}
local diceRolledNumber : number -- The number that the dice rolled on.
local function getDiceNumber() -- Calculates which number the dice rolled on by rotation values in the rotationTable and the bombOrientation.
local bombOrientation = bombClone.Orientation
for index, value in pairs(diceRotationTable) do
if bombOrientation == value + Vector3.new(0, bombOrientation.Y, 0) then diceRolledNumber = 1 break end
if bombOrientation == value + Vector3.new(0, bombOrientation.Y, bombOrientation.Z) then diceRolledNumber = 2 break end
if bombOrientation == value + Vector3.new(bombOrientation.X, bombOrientation.Y, 0) then diceRolledNumber = 3 break end
if bombOrientation == value + Vector3.new(bombOrientation.X, bombOrientation.Y, 0) then diceRolledNumber = 4 break end
if bombOrientation == value + Vector3.new(0, bombOrientation.Y, bombOrientation.Z) then diceRolledNumber = 5 break end
if bombOrientation == value + Vector3.new(bombOrientation.X, 0, 0) then diceRolledNumber = 6 end
end
end