Physics and Ragdolls
Build a collision model
Each separate object is converted into a convex hull. So you should have all faces that belong to a single convex object be a single smoothing group & texture. Also, it uses simple vertex connectivity to determine what an object is, so don't connect things you don't want turned into a single convex hull. Studiomdl does not optimize any of the meshes, it just makes convex hulls.
As a rule of thumb, you shouldn't model anything smaller than 1" cubed as a detail. You should be somewhat coarse in that regard, all details like bolts, buttons, etc should not be modeled as separate convex pieces.
In general, it's totally fine for convex pieces to overlap. So if this lets you make the model out of fewer (but larger) convex pieces, then that is good for performance. Please do so. You want to have as few convex pieces as possible. Number of vertices is less important, but it should be on the order of a lower LOD of the render model. You're not going to feel/notice inaccuracies of 1" in any cases - there are plenty of other factors that players will notice first.
$autocenter moves the model so that its origin is at the center of its bounding box.
It also adds an attachment point called "placementOrigin" which is the offset to the original origin.
This is useful for building gibs. You simply model them in XSI as a collection - where you'd want them to be placed. Then you export them separately and add
$autocenter to each qc. So they get reasonable origins (centered) for lighting, bboxes, etc and they spawn in the correct position when the parent model is gibbed.
- This lets you set the mass of the object in kilograms.
// set the mass to 100 kg $mass 100
- this will automatically compute the mass using density/thickness of the material applied and the collisionmodel itself.
// automatically compute mass $automass
- This tells studiomdl to assume the collision model is concave (i.e. a set of convex chunks). Normally, studiomdl assumes the model is a single convex.
// collision model is not a single convex piece $concave
Making a Ragdoll
Build a Collision Model
Using one of the existing characters as a guideline, build a set of separate objects (one for each bone). Make these objects as simple as possible, but don’t compromise the shape of the character too much. Keep in mind that the physics system is going to make each bone a convex object. It is not currently possible to make concave objects without using multiple bones. These models should be fairly low poly in general, and each vertex should be assigned to a single bone. It’s ok to leave holes in the skin (again, see one of the existing models like combine soldier or zombie).
You should only add collision objects for some of the bones in this model. If you put too many, you are just creating more work for someone else later. Performance limitations mean that we can only simulate somewhere between 15-20 bones per character and still hit our budgets. On bipeds, use an existing model as a template. In HL2, we’ve cut down bipeds for simulation as follows:
- We only support two spine segments
- Skip all fingers or toes
- Add-on equipment is usually merged in with another bone (like the combine soldier’s backpack)
The end result is about 15 bones for most human characters.
Export this model as an .SMD file, and name it
ragdoll.smd. Save it in the directory with the model’s other animations. You must export the .SMD as a reference frame (What does reference frame mean? it needs expanding).
Build the Ragdoll Pose
Pose the model in its most relaxed state. This pose will play the animation for each bone that isn’t being simulated. With humans, we’ve eliminated the fingers, so it’s essential that you pose the fingers in this animation. That way, if a character dies while holding a gun, he won’t fall over with his trigger finger out.
Export this pose as an .SMD (skeletal animation SMD or reference SMD?), name it
Add the ragdoll.qc File
If there is another character that uses the same or a really similar skeleton, simply copy its ragdoll.qc. Otherwise, copy
$hl2/models/ragdoll.qc to your model’s folder. Add a line at the end of the model’s .QC file that says
Build the Model
Run studiomdl on the model. It should tell you that it’s building a jointed collision model.
Run HLMV and Edit the Joints
Now run HLMV. First, check the Physics Model checkbox. Check over the wireframe physics model to make sure it built correctly and that your vertex assignments are ok. Click the physics tab. Now you can go through each axis of each joint and set the joint limits. Again, if you copy the qc file from another character, you can start with its joint limits. Be sure to set the mass to something appropriate (in kilograms). 1 kilogram is 2.2 pounds.
After you're done tweaking the limits, hit the Generate QC button. Now a new .QC file is on the clipboard. Paste it into your
ragdoll.qc and rebuild the model.