Rigidbody isn't moving but has velocity c#

Hello there, I have a problem with some dices to throw on a board and I’m not able to find an answer into the forums. I have been searching this for 3 days and I got nothing, so I decided to post the question here.

I’m creating a board game in C# and, of course, I have to do some dice rollings. I have a button that makes the dice roll when I press it and I have another function to set them to the original position to do another throw, but I have a problem at the time to get the values of the sides. I don’t know how to see when the dice are stopped to get the face values.

I got a script that gets the values but it gets all the values of the sides that collide with the board, not only the final side, when the die has stopped moving.

Here’s the die script:

using UnityEngine;
using System.Collections;

public class DieForce : MonoBehaviour
	public Rigidbody Body;
	Vector3 Traslation;
	Quaternion Rotation;
	public DieForce(Rigidbody rb)
		Body = rb;
		Traslation = rb.transform.position;
		Rotation = rb.transform.rotation;
	void Update()
	{	}
	public void roll()
	        UnityEngine.Vector3 force = Vector3.zero + new Vector3(9 + 6 * Random.value, .6F + 7 * Random.value, -10 - 4 * Random.value);
	   	Body.AddRelativeForce(force * 25);
	public void returnToPosition()
		Body.transform.position = Traslation;
		Body.transform.rotation = Rotation;
	public string getName()
		return Body.name;

The fact is that I have to know when the dice stop moving to get the values and continue the game (it’s a Risk-type game).

I’ve tried

if(rigidbody.velocity.magnitude == 0) {//do stuff}

but it never gets value 0, even if the die stops moving.

Another thing is that I have tried to use the coroutines to wait for the dice stop to continue the game and I’m not capable to do this.

My questions are:

  • How do I do to get when the dice stop?
  • How do I stop the game to wait for the die values?

I’ve found solutions to my problems in Javascript but I need them in C#. I will be very grateful for anyone who can help me. Thank you, I hope I’ve explained me enough.

I would consider printing the velocity its outputting. It’s probably extremely small.

When dealing with physics objects I tend to not check for == but rather that the velocity is <= a really small value.

if(rigidbody.velocity.magnitude <= smallValue) {//do stuff}

Well I couldn’t find a solution, so I decided to change my dice from moving rigidbodies to animated cubes with 6 animations (one for each side) depending of the result of a Random between 1 and 6.

Thanks a lot to all of you that wanted to help me with this problem :slight_smile: