- Home /
Active kinematic rigidbodies
Hello,
I'm trying to solve something with my NPCS that can get in a ragdoll state to fall with physics and stand up after a while.
So initially they are kinematics and moved by navmesh agent and when they go in ragdoll state they aren't kinematic anymore. The problem is all parts are detected as active rigidbodies even in normal state, even if I remove the colliders from those parts. How could I force them to sleep? Is it supposed to happen?
Thanks to enlight me!
Please guys i really need an answer for that.. I suppose this probably sounds like a silly question for some of you, so that means you could answer ;)
The problem is all parts are detected as active rigidbodies even in normal state, what do you mean by this
I mean they are not sleeping even if my NPC is not in ragdoll state(understand non influenced by physics, that means all colliders for all bones are deactivated and the rigidbodies attached to it are kinematics). I tried this morning to change the structure of my NPC to make the rigidbodies, colliders, joints and all attached stuff childrens of the bones (so I can deactivate them when wanted). They are no longer active in the physic engine but the ragdoll state is totally broken so I guess that was a bad idea too...
EDIT: Actually to make this more simpler, the problem occurs with every rigidbody attached to my NPC. They are set to kinematic but they are still active(not sleeping). I even put a key to set all active rigidbodies to sleep but that doesn't work meaning they wakes up instantly.
I read somewhere that a kinematic rigidbody should not use physics cycles. Here they say why a rigidbody would awake.
"another rigidbody collides with the sleeping rigidbody" $$anonymous$$y physic matrix should prevent that. The only collision i see is with the ground which is of course not a rigidbody.
"another rigidbody connected through a joint is moving." Sure they move but they are kinematics too and therefore should sleep also.
"when modifying a property of the rigidbody" I only set the is$$anonymous$$inematic to true or false when needed. Unless the changing position done by the parent is consider changing a property? In that case what should I do?
" when adding forces" I don't.
Do you mean that when the NPC is controlled by the navmesh you want it to be kinematic and so not affected by physics? Cause putting a rigidbody kinematic won't deactivate the collider component but only renders it useless cause you won't detect collisions anymore. So if your problem is that you have to manually deactivate the colliders when you want to.
"Do you mean that when the NPC is controlled by the navmesh you want it to be kinematic and so not affected by physics?"
yes, if the navmesh agent is active the NPC should not be affected by physics and my collisions are detected via a trigger.
"Cause putting a rigidbody kinematic won't deactivate the collider component but only renders it useless cause you won't detect collisions anymore. So if your problem is that you have to manually deactivate the colliders when you want to."
When exiting from ragdoll mode I deactivate bones colliders(not triggers) in the same time i put them kinematics, I also reactivate the normal collider of the parent (which is trigger) and events are received that way. When going to ragdoll mode it's exactly the opposite procedure.
Answer by barbe63 · Jan 20, 2015 at 07:47 PM
Wow i didn't lost my day!!
My solution to destroy rigidbody and to rebuild them makes my game run much faster on my mobile. The physic engine have 1ms of work when it was 10!! That progress is 10 times more than i expected and the same amount more of what i gained since I started to optimize my game (since about 2 weeks). I even think i will put my realtime shadows back and some timestep less!
@tanoshimi I wasn't sure i would gain performance by setting those rigidbodies to inactive since as you said i also thought that as long as they were kinematic the engine would barely take them in account. But now i know I was wrong! (and that i was right to search this way ^^)
Thank you guys, my solution is not yet the same results i had but almost and i really gained a lot!
EDIT:Indeed! Now my game can run really nice with some realtime shadows and 1.5 time step instead of 2. I like this day :p
Answer by ricardo_arango · Jan 20, 2015 at 05:59 PM
You can force an object to Sleep for one frame using Rigidbody.Sleep. If the object is in contact with other objects, in a hierarchy of rigidbodies (not recommended), connected via joints, has forces are applied to it via scripting, it receives gravity, etc (what's described in the page you linked http://docs.unity3d.com/432/Documentation/Components/RigidbodySleeping.html), it will be awaken or kept Awake. For a rigidbody to sleep it needs to be resting with no forces being applied to it.
Note that is not recommended to have multiple Rigidbodies in a hierarchy of objects, but instead a single "root" rigidbody.
You can affect how quickly a Rigidbody comes to rest with the sleepVelocity and sleepAngularVelocity components.
Why do you need to Rigidbody to be inactive?
I did the Sleep() fonction in a script that detect all non sleeping rigidbodies. That doesn't work since they probably wakes up instantly.
I have to make all those individuals rigidbodies in the same hierarchy so i can use the bone system. What are joints for then?
i need them to be inactive so the physic engine have 10 times less work to do with active rigidbodies.