Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

SkinnedMeshRenderer Ragdoll

Discussion in 'Scripting' started by Themp, Mar 13, 2013.

  1. Themp

    Themp

    Joined:
    Nov 8, 2011
    Posts:
    96
    Hey guys.

    I'd like some insight on how to activate the ragdoll effect unity says it has on the SkinnedMeshRenderer page.
    right here:
    http://docs.unity3d.com/Documentation/Components/class-SkinnedMeshRenderer.html

    Code (csharp):
    1.  
    2. "the main advantage to using boned characters in Unity is you can enable the bones to be affected by physics, making your characters into ragdolls. You can enable/disable bones via scripting"
    I have boned characters from both Maya and Max so this should just work

    the problem is.. Nowhere can i see an option of enable gravity or enable bones or anything like it what would cause the character to go ragdoll like

    How do I do this without using the ragdoll wizard (because that one really sucks)
     
  2. Glockenbeat

    Glockenbeat

    Joined:
    Apr 24, 2012
    Posts:
    669
    Actually the ragdoll wizard simply attaches rigidbodies to the specified bones and distributed the mass accordingly. Also joints are produced to make sure your ragdoll does not go nuts.

    You can actually do that all by yourself and manually as well, you don't need the ragdoll wizard for that.

    To enable the ragdoll you just need to cycle through all the rigidbodies of the ragdoll and make sure that they are set to .isKinematic = false. Boom - physics.

    edit: And of course you'll want to stop any animations as well.
     
  3. Themp

    Themp

    Joined:
    Nov 8, 2011
    Posts:
    96
    but there are no rigidbodies on it except for the main parent;

    parent (rigidbody,navMeshAgent,skinnedmeshrenderer,AIScript)
    \
    |---Polysurface
    |---root_bone
    \ alot of child bones

    this is my structure..
     
  4. Glockenbeat

    Glockenbeat

    Joined:
    Apr 24, 2012
    Posts:
    669
    Even after using the ragdoll wizard and dragging all the corresponding bones into their slots?

    The rigidbodies are not assigned during import or by default. You need to do this either using the ragdoll wizard or manually. Or with one of the ragdoll plugins from the asset store.
     
  5. Themp

    Themp

    Joined:
    Nov 8, 2011
    Posts:
    96
    No i meant with the skinned mesh renderer ragdoll I want THAT one working, I don't want another prefab of the ragdoll version of it (which i'll get by using the ragdoll wizard)

    also the feet will fall through the ground if i use that.. I even tried selecting the toe bones but alas it had no use..

    I will get everything right except the lower parts of the leg (again IF i use the ragdoll wizard)
     
  6. Glockenbeat

    Glockenbeat

    Joined:
    Apr 24, 2012
    Posts:
    669
    Again, the ragdoll wizard is not doing anything different than assigning rigidbodies, joints, colliders (missed this one before, sorry about that) and masses to the body parts. You can do that via script as well!
    You just need to make sure to be able to identify the bones correctly (most likely by a unique naming convention) and set everything up accordingly.

    So something like this actually has the same effect (just a quick code sample, can be better of course):

    Code (csharp):
    1.  
    2. foreach (Transform trans in GetComponentsInChildren<Transform>()) {
    3.     if (trans.gameObject.name == "Character_Head") {
    4.         BoxCollider col = trans.gameObject.AddComponent("BoxCollider");
    5.         Rigidbody rigid = trans.gameObject.AddComponent("Rigidbody");
    6.         // .... and so on
    7.     }
    8. }
    9.  

    edit: Your assumption seems to be that the ragdoll properties are available on bones right after import, nothing else to do. This is not the case and the documentation does not do a good job on clarifying this. Bones are just usual Transforms. You need to assign these physics components in order to get ragdoll working.
     
    Last edited: Mar 13, 2013
  7. Themp

    Themp

    Joined:
    Nov 8, 2011
    Posts:
    96
    "This is not the case and the documentation does not do a good job on clarifying this. Bones are just usual Transforms. You need to assign these physics components in order to get ragdoll working."

    thanks.. THATS something I wanted to know.. Indeed the documentation sucks

    seems the only way to go is go nag to my 3D artists about the bone naming and finding out why it excludes the legs