I am trying to create a 3D dice for a game. Normal dice has been created by setting cube for dice with Rigidbody and apply force to throw a dice.

Now the problem is, the user wants to give a value 1 - 6 in the text box then they will press the roll button. The dice have to rotate and need to show the dice value as the user enters in the text field once it stops rolling.

For example:

  1. In the Input box the value entered as 5,
  2. Now the dice want to roll on the table and show the value as 5.

Anyone, please help me to solve this

Thanks in Advance

  • 1
    \$\begingroup\$ You probably can simulate dice roll before the user presses the button. Now, when you know where dice sides will end up, apply initial rotation to compensate. \$\endgroup\$ – trollingchar Apr 25 '19 at 14:50

I wouldn't rely on the physics for this. If you have one dice, then you should just have some prebaked animations. You can have more than one animation per outcome to add variation. If you have multiple dice then we can take a different approach. Prebake several animations (you can use physics and record the keyframes) for rolling the dice. For each dice, mark the side that ends up face up at the end of the animation. When the user rolls the dice, select a random animation (multiple animations so it's not obvious they are prebaked) then find the side of each dice to set that ends faceup at the end of the animation. Find where that face is at the start of the animation. Rotate the dice as a child object before the animation (or swap texture UVs) such that the side you want up is in the correct position before the animations starts. In this way you can rig the dice roll.

For example let's say normally the 2 ends up on top for Animation A. At the start of the animation, the 2 side is facing in the -y direction. The user picks the 1 side. Rotate the dice at the start of the animation so the 1 side is facing the -y direction. Now at the end of the animation the 1 will end up on top.

It's difficult to explain clearly but hopefully you get what I'm trying to say. If not, comment.


If you are determined to do this strictly with physics in unity with rigidbodies..This is a somewhat silly answer but what about making a "loaded dice"?

Make a die that is comprised of 3x3x3 set of cubes. Each cube's mass can be modified via a script that is interacting with your input fields from your UI with C#.

If a user inputs "1" for example and the desired 3D dice roll result is a "1" you would make your UI input script look for "1" and as a result increase the mass of the 9 cubes on the side that your "6" is on , or whichever side is opposite to the "1".

This weighting process is not guaranteed to work but im sure if you adjusted the parameters enough you could find a nearly optimal solution using physics.

Hope this helps! I like the other replies as well. Very fun problem here..

EDIT: My father is a machinist and has told me that weighting the corners of the dice was a tactic used by fabricators of these "loaded dice". I hope this helps.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.