Keep Rigidbody awake

Hey guys,

I’m having one rigidbody that I would like to keep checking for collision with colliders. So instead of providing a lot of rigid bodies to all the items in the world, my idea was to have that singular item to have the rigid body and collision check (see it like a trigger for all items in the world).

The problem is that the physics system in Unity makes the immovable item with the rigid body going to sleep, so I’m trying to find a way to keep this rigid body awake. Setting the sleepVelocity and sleepAngularVelocity to 0 doesn’t do anything…

I’m now left with calling the WakeUp function every frame, bypassing the physics engine’s desire to sleep, but I don’t think this is the most suitable way.

Does anyone of you have any suggestions?
Thanks in advance

Thinking about what you are trying to accomplish and reading over the other things I saw last night after my other post, I’m not sure you have an issue.

According to the materials here:
http://unity3d.com/support/documentation/Manual/Physics.html
you do not want to move “static colliders” because it changes the static evironment physics calculations, which is CPU intensive.

What might be a better option for you is using kinetic rigidbodies? They are essentially the same thing as a static collider, but they are only included in the physics calculations when they are told to move OR another rigidbody collides with them.
References to waking/sleeping here:
http://unity3d.com/support/documentation/Components/RigidbodySleeping.html

Also, in the “hints” section at the bottom of this page:
http://unity3d.com/support/documentation/Components/class-Rigidbody.html
it says
“If you are moving a GameObject through its Transform component but you want to receive Collision/Trigger messages, you must attach a Rigidbody to the object that is moving.”
so maybe you can’t do the trigger thing like you are saying, without adding at least doing a rigidbody kinematic thing…?

This might all be stuff you’ve gone over, and I just woke up. Hope it helps though.

you can change the sleep settings in edit → project settings → physics → sleep velocity/sleep angular velocity

setting them to 0 should keep the rigidbodies awake, it will be taxing on your cpu and battery though.

i saw another post about adding any force will keep it awake, even 0 force. i haven’t tried this yet though.

other post: Rolling ball gets stuck in corners - Questions & Answers - Unity Discussions

Try this!
Inside the Update () of any script attached to the rigidbody which uses as collision check, add:

transform.position = transform.position;

That should do the trick:)

This is weird.
According to the docs sleepvelocity and angularsleepvelocity represent the thresholds below which rigidbodys fall asleep. The lowest value for both is 0. As far as I know there’s no velocity smaller than 0, since velocity is a force vector, except in another dimension maybe.
In my opinion, this is a bug because this should be as easy as it sounds.

I don’t consider bad code calling WakeUp every frame. Its just OK. I looked at profiler. Its not doing any lag at all.

Works for me:

 void Update () {
     if (rigidbody.IsSleeping())
         rigidbody.WakeUp();
 }