Search code examples
unity-game-enginegame-physicsdice

Dice rolling simulation: landing on the edge?


I'm trying to implement my own version of a dice roller.

So far I've reached a decent result, my solution is not very flexible yet but I like the realism of the physics.

I have an issue, though: sometimes a dice lands on it's edge and it keeps that unnatural position for the rest of the time.

How can I avoid it?

I tried to tweak the physics materials, the rigid body simulation, the scale of the dice and the system gravity with no success.

Maybe I did not find the right mix or maybe I'm missing something.

I will appreciate any suggestions thanks![Dices


Solution

  • you can iterate thorugh your dice, find ones that are sleeping (Rigidbody.IsSleeping) and for those that are check the angles are not wierd (i.e. one of the angles should be close to multiplies of 90), and apply some random torque for those that are likely to stand on edge