Search Unity

Ragdoll

Discussion in 'Scripting' started by Mr. Animator, Oct 4, 2005.

  1. Mr. Animator

    Mr. Animator

    Joined:
    Oct 2, 2005
    Posts:
    193
    Can anyone give me a general idea of one approach to ragdoll physics within Unity? I'm trying to set up a very simple little test with a primitive character brought in from maya just slumping to the ground. So my plan is to have attached to each joint in the maya skeleton both a rigidbody and a collider of some kind. That much I've completed, and my little primitive man successfully falls to the ground and breaks into pieces. Now I assume that hinge joints are at the core of making a so-called 'rag-doll' but I'm having a hard time setting them up.

    For starters... should the hinge joints radiate OUT from his center of mass, or inward? And is there a way to visually see the anchor point of a hinge joint in your 3d scene, or do you just have to use your imagination? Am I totally going about this the wrong way? Any general tips or theory behind such a task would be helpful.
     
  2. Mr. Animator

    Mr. Animator

    Joined:
    Oct 2, 2005
    Posts:
    193
    Okay, as I tend to do, I ended up figuring out a lot of this stuff on my own after asking... springs seem to be the key to taming most of the anomolies I was dealing with. However there's still one thing that seems to crop up a lot. For the purposes of this test, I'm using a prim cube as my ground surface, and my ragdoll guy seems to really like passing through it once he finally comes to rest. He reacts properly to it up until his movement slows, and then he just pops right through it. Any guesses as to why he'd so readily fall through?
     
  3. robertseadog

    robertseadog

    Joined:
    Jul 23, 2005
    Posts:
    374
    Not really, but if you seearch there should be a simple rag-doll file somewhere in the forum ;)
     
  4. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    You should put primitive colliders on the parts of the ragdoll (as opposed to mesh colliders) if you haven't done already. Otherwise, I'd suggest reducing the time step in the Physics properties of the project. A smaller step will mean more precise physics calculations of course at the expense of well, more calculations. :)

    -Jon
     
  5. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    As aarku says, primitive colliders are the way to go. In the case of humans , capsule colliders are best and a box for the chest.

    The problem with connecting the skeleton with hinges is that it is easy to get a connection wrong. Thus i would do it step by step, so you see immediately when something goes wrong in the setup. Eg. Start by connecting the left lower leg with the upper leg. Then connect upper leg with hip etc.

    I had best success with ragdolls when putting the hingejoint anchor at the origin of the transform. The hinge axis is visualized with an orange line. This can be invisible because the transform axis are drawn on top of it.
     
  6. Mr. Animator

    Mr. Animator

    Joined:
    Oct 2, 2005
    Posts:
    193
    Ah, I found why I was falling through the floor...

    At the top of my heirarchy (the root joint of my guy) I had a rigidbody that was being effected by gravity, but had no collider of its own. So while all of the children of that root were falling correctly and hitting the floor, there was a parent object that was falling infinitely downwards, and when the simulation went to sleep, it would rip the children violently through the floor to catch up to the root.

    Whoops.

    Now I'm wondering for shoulders - can you have a hinge that is capable of swinging in more than one axis freely? It seems like the only examples I've seen just have the shoulders dropping in one axis. The only real reason this is a problem is because I want to have a character that switches to ragdoll in the middle of an animation, but if the animation has the shoulders posed in more than a single axis then the hinge causes those other two axes to zero out... rather violently too, which tends to cause a wiggle throughout his body.

    Any suggestions?