Rigidbody not waking up

Hi,

I seem to have a problem with rigidbodies not waking up. I have 2 dice in my scene, when I press a button I change their position using their transform, use rigidbody.wakeup() and addForce but they are very stubborn about waking up. They usually wake up when I hit this button 2-3 times, so it seems like it registers as woken up after a frame, but I need them to wake up now. Is there a problem prone way to wake up rigidbodies?

here is my code:

    void OnClick()
    {
      //  dice1.rigidbody.isKinematic = false;
      //  dice2.rigidbody.isKinematic = false;

        Vector3 pos = new Vector3(0.3f, 1.5f, -0.4f);
        dice1.transform.position = pos;
        pos.x = 0.5f;
        dice2.transform.position = pos;

        dice1.rigidbody.velocity = Vector3.down;
        dice2.rigidbody.velocity = Vector3.down;

        dice1.rigidbody.WakeUp();
        dice2.rigidbody.WakeUp();

        dice1.GetComponent<gameDice>().Rolled = true;
        dice2.GetComponent<gameDice>().Rolled = true;     

        dice1.rigidbody.AddForce(new Vector3(Random.Range(20, 40), 0, Random.Range(20, 40)));
        dice1.rigidbody.AddTorque(new Vector3(Random.Range(1, 20), 0, Random.Range(1, 20)));
        dice2.rigidbody.AddForce(new Vector3(Random.Range(20, 40), 0, Random.Range(20, 40)));
        dice2.rigidbody.AddTorque(new Vector3(Random.Range(1, 20), 0, Random.Range(1, 20)));

        if (dice1.rigidbody.IsSleeping())
            print("still sleeping");
    }

I would appreciate any help!,

Thanks

You don’t need WakeUp if you’re adding forces. You need to wait a physics frame before IsSleeping will return true since the force hasn’t taken effect yet when you do the print statement.

–Eric

Hi thanks!

With that information, I’m delaying my calculation for 1 frame using a bool value. It’s working now.

Thanks!