- Home /
Why are my Rigidbodies not sleeping?
I have a zero-gravity scene and some Rigidbodies floating in space that I can kick around. They have some drag, so once you kick a body it'll float for a bit and then come to a stop. By "kick" I mean applying a single, one-off force. I am not applying any subsequent forces or forces over time.
In PhysicsManager, I've set the Sleep Velocity and Sleep Angular Velocity both to 1. My understanding is that once a body's velocity falls below these thresholds, the body will go to sleep.
The behavior I'm actually seeing is that my bodies remain awake until both their velocity and angular velocity have reached true zero, and then for several seconds afterward. Some bodies seem to remain awake indefinitely. I can inspect such a body in the scene and see that it is not in contact with anything; and using a debug display to show its current rigidbody.velocity, rigidbody.angularVelocity, and rigidbody.IsSleeping, I can see that both properties are true zero, and IsSleeping is FALSE.
I can't for the life of my figure out why?
In searching around for answers, the most common suggestion I saw looks like:
// on the RigidBody
void FixedUpdate()
{
if(rigidbody.velocity.magnitude < someSleepVelocity)
rigidbody.Sleep();
}
Seems simple enough in theory, but my problem is that I have a very large number of rigid bodies spread throughout the scene, so running this code on all of them all the time becomes extremely performance-prohibitive. And besides, it seems redundant, no? Isn't this exactly what the PhysicsManager sleep thresholds are supposed to be doing?
if you have a debug on this script, and this script is attached to all the rigidbody objects you will have no way to tell which log is from which object. Seems like a bad use of RB sleep as well, probly be much more efficient to just let them keep floating rather than running fixed update on X amount of objects.
I would try turning max angular velocity to 1 (or maybe 0.5) as well and see if the game works correctly (simply for debugging reasons).
Also, maybe try different Physics pushes like for forcemode use impulse ins$$anonymous$$d of velocitychange or vice versa. http://docs.unity3d.com/Documentation/ScriptReference/Force$$anonymous$$ode.html
As I recall, if any script is used on the object, it will wake up (maybe it's just physics script, idk).
Your answer
Follow this Question
Related Questions
How to stop rigidbody.sleep() 2 Answers
Rigidbody not sleeping 1 Answer
How do I change force of gravity for a single object? 4 Answers
Getting 'Real' behavior through physics settings 1 Answer
Move armature rigidbody character 2 Answers