1
\$\begingroup\$

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

\$\endgroup\$
1
  • 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\$ Commented Apr 25, 2019 at 14:50

3 Answers 3

4
\$\begingroup\$

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.

\$\endgroup\$
3
\$\begingroup\$

Revisiting this question, I just got a new idea: you could make a physics simulation in the background and cache the result, determine which face ended up, put the textures in the right place and play the simulation back to the user.

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .