Setting up Ragdolls for Custom Joint Hierarchies

From The DarkMod Wiki
Jump to: navigation, search

Originally written by oDDity on http://forums.thedarkmod.com/topic/2540

This tut assumes that you know how to set up a character and it's def file and can spawn it in doom.

For this tut I used a totally custom mesh, skeleton hierarchy and naming convention which is very different from the doom models - it makes no difference what you call your bones, how how the skeleton is made.

This is not the way you *have* to do things, I just documented the way I set up a decent basic ragdoll on an entirely custom character from scratch.

The basic hierarchy of my skeleton was

                                  shoulder-arm-armroll-forearm-forearmroll-hand
              spine-spine1-spine2/
origin - hips/                   \ 
             \                    neck-head
              \
               upleg-uplegroll-leg-legroll-foot-foot2-toebase

First of all you need an af_pose.md5anim for your character. It just needs to be one frame where all the bones have a key set on them.

Make an initial AF file using the afeditor. We'll call this one 'myragdoll.af' save it in doom3/models/af

Point to this af file in the entitydef section of your character's def file, the character model in this example is 'revenant'.

entityDef revenant
{
   "model"       "revenant"
   "ragdoll"      "myragdoll"
  • Restart the doom editor.
  • Make a room in doom to as a testmap.
  • Type 'editafs' in the console to bring up the AF editor.
  • Browse to your 'myragdoll' af file from the dropdown menu at the top.
  • Go to the properties tab and write the name of your charcater's def file where it says 'model:'
  • Go to the bodies tab, and there should be a default one called 'body'.

If the 'new' button is greyed out, it is becasue you have not pointed it to a model, so go back to the properties tab and type the name of your def file again.

Always hit the enter key after typing anything in any of the boxes in the afeditor or picking anything from dropdown menus, and then hit the save button at the bottom, because it has a habit of reverting your changes back to defaults if you don't.

You may have to restart the afeditor, or doom, or just select a different af file from the dropdown menu at the top and then select you myragdoll one again to refresh it, but if you are pointing to your models's af file in the properties tab, the 'new' button on the bodies tab should not be greyed out.

The first thing to do is to rename that default body 'body' in the bodies tab, to 'waist'.

If I dont' say to change a setting than just ignore it and leave it at default.

Settings for this first body 'waist' are:

  • Type = box
  • Length, Width, height will vary, but call it 10, 10, 10 for now.
  • density = 0.2
  • Position is set to joint, this will position the box shape ariound the specified joint. I set this to the 'hips' bone.
  • Modified joint = origin
  • contained joints = *origin -*spine

as you can see, I set it to affect the whole of both legs for now, but this will change later.

Make a new body called "chest".

Settings are the same as before except on the position tab

  • joint = spine2

and on the joints tab

  • modified joint = spine1
  • contained joints = *spine1

I set this to affect the whole of the upper part of the model for now.

Now go to the constraints tab and make a new one called 'waist'

  • type = universal
  • body1 = chest
  • body2 = waist
  • anchor = joint = spine1
  • shaft1 = angles
  • shaft2 = angles
  • limit type = cone = 90
  • limit orientation = angles

The exact numbers will always depend on your models. Now to see if the ragdoll is working, hit F2, load the testmap, bring up the console and type

spawn revenant

replacing 'revenant' with the name of your character's def file, obviously.

When it's spawned, kill it - it's a good idea to set it's health to 1 in the def file. When it's dead, bring down the console again and type

af_showbodies 1
af_showbodynames 1
g_dragentity 1

Now you should be able to lift the dead model with your cursor and you should see two yellow boxes, one in his chest and one in his hips area. These are the two bodies, 'waist' and 'chest' which you created. You can adjust the size of these bodies - which are actually collision boxes for your ragdoll - by changing the length, width, height numbers in the bodies tab.

alt+tab back to the editor

Now to make one for the head

Create a new body called 'head'

  • type = box
  • position - whatever suits your model best, I used joint = head

If you haven't got a bone in a conventent place to center the head collision box, then use coords.

  • Modified jont = neck
  • contained joints - *neck

Now you have to go back to the chest body and change it's contained joints, because before we included everything above spine1. Change the chest contained joints to *spine1 -*neck

You cannot have the same bone present in more than one body.

Make a new constraint called 'head'

  • type = universal
  • body1 = head
  • body2 = chest
  • anchor joint = neck
  • limit type = cone

Now you can f2 into the game again and drag your model to see the new head box. Now all we need are the limbs.

Make a new body called Rupleg

  • type = box
  • length = 5
  • height = 20
  • width = 5

I was able to position the box to fit the thigh by using joint = rightuplegroll, because that is the center of the models thgh, but if you just have one long thigh bone, then you'll have to use the upleg joint or coords.

  • modified joint = rightupleg
  • contained joints *rightupleg -*rightleg

Make another new body called 'rlowleg'

  • type = cone
  • size= adjust to your model
  • position joint = rightleg (right shin bone)
  • modified joint = rightleg
  • contained joints = *rightleg

We use a cone here, becasue the point of the cone starts at the knee and spreads out as it reaches the foot, so it basically takes in the foot as well. You really don't want to be making a separate foot body.

Make a new constraint called 'rightupleg'

  • type = universal
  • body1 = rightupleg
  • body2 = waist
  • anchor joint = rightupleg
  • limit type = cone = about 60

Make another new constraint called 'rightlowleg'

  • type = hinge
  • body1 = rightlowleg
  • body2 = rightupleg
  • anchor joint = rightleg (your shin bone)
  • axis = angles 0, 270
  • limit = angles = 130, 70, 90

These hinge joints can be a pain to get the setting right on, but there's a good description at iddevnet.

Now F2 back into the game and check the results. Toss the doll around a bit to see if the knee bends correctly. If not, you'll have to chage the numbers on the hinge joint.

Do exactly the same for the other leg.

Now, you must go back to the waist body, which currently has it's copntained joints taking in the legs as well, and change it to ignore the legs.

  • contained joints = *origin -*rightupleg -*leftupleg -*spine1

Now lastly, the arms:

Make a new body called 'Ruparm'

  • type = bone
  • joint1 = rightarm
  • joint2 = rightforearm
  • width something small like 5
  • modified joint = rightarm
  • contained joints = *rightarm -*rightforearm

This is set to bone, rather than a box, and will give a diamond shape which will fir the bone, so as not torestrict the movemnt of the arms too much.

Make a new constraint called 'Ruparm'

  • Type = universal
  • body1 = ruparm
  • body2 = chest
  • anchor joint = rightarm
  • shaft1 angles = -270, 0
  • shaft2 = -90, 0
  • limit type = cone = 95
  • limit orientation angles = -270, 0

You may need to change some of these numbers to suit.

Make a new body called 'Rlowarm'

  • Type = bone
  • joint1 = rightforearm
  • joint2 = righthand
  • width something like 5
  • modified joint = rightforearm
  • contained joints = *rightforearm

Make a new constraint called 'Rlowarm'

  • type = universal
  • body1 = Rlowarm
  • body2 = Ruparm
  • anchor joint = rightforearm
  • shaft1 angle = 0, 270
  • shaft2 angle = 0, 90
  • limit type = cone = 60
  • limit orientation angle = 0,270

Now you must go to the chest body and change it's contained joints to

*spine1 -*neck -*leftarm -*rightarm

For those who dont' know, putting a * before the names tells doom to include every bone in the hierarchy which comes after the *, putting a -* means to exlude every bone which comes after the -*.

Now do the same for the left arm as for the right, and you should have a good basic ragdoll. You could go on to add hands as separate links if you want to, but it's hardly necessasry. You should be seeing a pattern emerge from all of the above, so adding a couple of hands as hinge joints shouldn't be hard to figure out.