Search Unity

Proper/optimized way to ragdoll an animated character

Discussion in 'Scripting' started by TheTortilla, Jan 7, 2018.

  1. TheTortilla

    TheTortilla

    Joined:
    Nov 25, 2013
    Posts:
    38
    Hi everyone,

    I'm developing a VR FPS game on Windows that will need the use of ragdolls for death.

    For now, I used the built-in wizzard to create ragdolls for my animated characters. When the character dies, I disable the animator, switch the rigidbodies from kinematic to non-kinematic, and enable their collision detection. The problem is that there is no way to disable completely the rigidbodies.

    https://docs.unity3d.com/ScriptReference/Rigidbody-isKinematic.html

    Unity documentation advices to proceed the way I did. The problem is that when the character is not ragdolized, rigidbodies create massive overhead on Physics and scripts when they are moved by the scripts and by the animator.

    Is there a better way to "disable" Rigidbodies?

    I've tried pooling a second character as ragdoll and replacing on death, the issue is that it seem to glitch with physics and the ragdoll has weird behaviour, probably due to the fact that I update all transforms at once on death to make it match the previous character's animation.

    Do you have other solutions?

    Thank you for your help!
     
  2. arfish

    arfish

    Joined:
    Jan 28, 2017
    Posts:
    782
    Have you tried to remove the Rigidbody component?
    Code (CSharp):
    1. Destroy(Object.GetComponent<Rigidbody>());
     
  3. TheTortilla

    TheTortilla

    Joined:
    Nov 25, 2013
    Posts:
    38
    Hi, thank you for your answer!

    This won't work because it will break the joints relationships between the limbs of my ragdoll
     
  4. TheTortilla

    TheTortilla

    Joined:
    Nov 25, 2013
    Posts:
    38
    I have still not found an answer to my issue.

    I'm very surprised because ragdolls seems to be a common practice in most games today, and the "default" way (switching from kinematic to non kinematic) seems to perform very bad due to heavy unnecessary continuous computations.

    Removing rigidbody is also pretty unpredictable, I think it's because it sometimes involve weird recomputations of what unity consider to be the "static collision world".

    Not having colliders is not an option for a shooter, but those colliders are just used for raycasting, no actual mesh to mesh collisions. But apparently there is no way to disable mesh/primitive intersection computations in Unity.

    So my question is:

    What is the standard clean and well performing way to implement animation to ragdoll for FPS in Unity?

    Isn't there at all a way to involve all these heavy unnecessary computations?

    Please, I need help...
     
  5. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    You can also raycast triggers, not sure if its the solution, just putting it out there
     
  6. TheTortilla

    TheTortilla

    Joined:
    Nov 25, 2013
    Posts:
    38
    Thank you for your answer, but setting colliders as triggers doesn't seem to change anything on "overlap" computations...
     
  7. dibdab

    dibdab

    Joined:
    Jul 5, 2011
    Posts:
    976
    put kinematic colliders on separate layer to minimize performance impact
     
    SparrowGS likes this.
  8. TheTortilla

    TheTortilla

    Joined:
    Nov 25, 2013
    Posts:
    38
    No, I tried, layers don't seem to avoid computations, they only avoid "physics behaviours" computations. the only thing that seem to work is to disable colliders when not raycasting. but it results in CPU spikes and seems too dirty to be the "right way" to do it.

    I'm pretty sure I'm missing something simple, I can't believe there would be no way for Unity to do character hitboxes/ragdolls without all these unnecessary computations.

    Please, help!
     
  9. nypehb

    nypehb

    Joined:
    Aug 14, 2020
    Posts:
    8
    I have the same problem :-(. Does anybody know how to solve this problem?
     
  10. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    510
    It’s not really the kinematic rigidbodies that are causing the overhead it’s the joints. The joints cannot be turned off and a lot of them can be a drain n the physics engine.

    that’s said, I’m still looking for the best way to do it myself. I spawn in ragdolls for my characters, but it’s not perfect.

    I currently have problems with getting the exact velocity for each limb to be transferred properly.
     
  11. arfish

    arfish

    Joined:
    Jan 28, 2017
    Posts:
    782
    How about using LOD, or another criteria to switch between a ragdoll model, and a simplified animated version?