I am working on a dice game in Unity. The dices are meshes with rigid bodies. 3 dices are thrown in to a box using AddForce.
The problem I am having it due to the sides of the box or due to other dices sometimes the dices do not turn fully to a face. So it is confusing to the player to understand which side has turned up
If someone has done similar game is there a solution for this?
Hi,
I recently hit the same problem, I resolved it by giving the die or dice which are not facing up a small kick if their rigid body velocity is 0 and its not possible to determine which side is up. Something like this attached to each die …
public class DieController : MonoBehaviour {
public int value = 0;
private Rigidbody rigidbody; //Get this in Start()
private int DetermineUpSide() {
//This method will return 1 .. 6 unless the side can not be determined, in which case it returns 0
}
private void Update() {
if(rigidbody.velocity == Vector3.zero) {
value = DetermineUpSide();
if(value == 0) {
rigidbody.AddForce(new Vector3(Random.Range(0.5f, 1.0f), Random.Range(0.5f, 1.0f), Random.Range(0.5f, 1.0f), ForceMode.Impulse);
}
}
}
}
Its not perfect, but, it works!!
Hope it helps!