Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm having this problem in the free edition of Unity 4.1 where rigidbodies aren't falling asleep (and yes, I've tried playing with the sleepVelocity and sleepAngularVelocity values!). I've read the docs at http://docs.unity3d.com/Documentation/Components/RigidbodySleeping.html but cannot figure out the problem.

Here is a screenshot demonstrating my problem: Rigidbody Sleep Diagram

I wrote a script that is attached to the rigidbodies in question, which sets the material color to red if the rigidbody is currently asleep or green if it is awake. The screenshot was taken when all objects were at rest. As you can see, not all of the gameobjects are sleeping. Each piece of debris you see on screen is its own gameobject with a rigidbody and collider.

The Unity docs I linked to above state the following:

Rigidbodies automatically wake up when:

  • another rigidbody collides with the sleeping rigidbody
  • when adding forces.

Perhaps some clarification on the above might help solve this issue: If two rigidbodies are touching when they fall to "rest", will they never stay asleep? Put another way, would they just keep interrupting each other's sleep? As for the "adding forces" part, do sleeping rigidbodies awake only when forces are added directly to them, or when any force is added to any object (this is important because I am using a rigidbody character controller which moves via AddForce() calls)

I have tried manually sleeping objects myself with undesired results. What usually happens when I do this is that some objects will remain suspended in the air.

Let me know if you need other details - I have tried a great deal of things.

share|improve this question
add comment

2 Answers

Rigidbodies awake when any force is applied to them. If you had a pool game and all the balls are sleeping and you would hit them with another ball, they would all wake up.

I guess there is some minimal jittering going on that keeps your rigidbodies alive. There are a lot of parameters that can have an impact on this, but personally I would first and foremost look into these:

  • Use a Physics Material for your colliders and start with high friction values and no bounciness.
  • Increase the Drag and AngularDrag values of your Rigidbodies so that the objects would come to rest by themselves even if they don't collide.
  • Use a sleepVelocity value that is appropriate for the scale of your level. Remember that 1 unit in Unity is 1 meter in the physics-engine. Ideally your objects would be in a realistic scale.
  • Maybe also try increasing the Min Penetration for Penalty value in the physics settings. This also depends on your world scale.
share|improve this answer
    
Unfortunately, I've tried all of the above and it had little impact on the outcome. –  Ryan Berserkguard Nørby Aug 22 '13 at 2:49
2  
I have to comment something totally unacceptable on this.. I hate it when i try to play "pool" and my balls are sleeping. Haven't tried hitting with other ball thou.. –  Katu Aug 22 '13 at 5:20
add comment

In the end I solved it by manually figuring out when to destroy the rigidbodies and colliders. I created a box collider trigger that goes from the floor to the player's knees. When an object breaks (and the GameObject is replaced with the broken version), there is a script that checks every 5 seconds to see if any of its rigidbody children are fully enclosed by the trigger. The script then destroys any rigidbodies and colliders that meet this criteria and stops polling.

It feels a bit hackish, and only works for my specific use case, but it gets the job done. Even after breaking several hundred objects in rapid succession, the physics isn't getting overloaded like it was before.

If anyone thinks of a more elegant solution, please let me know!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.