From Valve Developer Community
Revision as of 11:50, 9 April 2012 by Shawnolson (talk | contribs) (fixed a couple typos and included internal links to 3d apps)
Jump to: navigation, search

Attachments are hooks for the placement of sprites, weapon models, or other in game entities on the model. If you need particles to come out of a particular point on a gun, or you want to glue items onto characters in the game, then you'll want to use attachments.

Every attachment point must be attached to a bone, and its position in space is specified relative to the bone's coordinate system.

To define an attachment point, you need to add a line in .qc file.

$attachment (name) (bone name) (X) (Y) (Z) ["absolute"] ["rigid"] ["rotate" pitch yaw roll] 

For example:

$attachment NAME "ValveBiped.NAME" 0 0 0 rotate 0 0 0
Note.png Note: Have no quotes on NAME. This will enable the use of attach points on the null objects instead of specifying one.

Attachment is defined as a point offset from a parent bone - i.e. the important components are the bone it's parented to, a position offset and a rotation.

You can view/tweak attachment settings in HLMV.exe. Click attachments tab to see the list of attachments for the model. You can enter the offset in translation/rotation fields to preview the attachment location. If you are happy with it, copy generated QC String back into your .qc file and re-compile the model.

Attachments usually have their parent bone defined in the 3d package (in XSI, 3ds Max or Maya). You can also use a 'null' as a parent bone, as it will be exported as a bone node in a SMD. When adding bones for attachments, make sure you have any "export unused bones" options turned on for this to work. Then add an attachment setting line pointing that bone to your .qc to create one.

Automatically attaching objects to characters

Entities in the game which are linked to parent entities using the "bone merge" option (EF_BONEMERGE in the source code) can be automatically snapped to the correct bone. Weapons use this for instance to make sure they appear in the correct hand.

To set this up, create a parent bone for your attachment model named identically to the bone you want it attached to. For instance, if you want your pistol to always link to the character's right hand, make sure it has a parent bone called SK_R_Hand (assuming this is the name of your character model's right hand. For HL2DM models, name it ValveBiped.Bip01_R_Hand).

After compiling the mdl, it's a good idea to load it up in the HLMV and make sure the parent bone is there (SK_R_Hand). If it's not, chances are you haven't ticked that "export unused bone" option in the exporter.

To avoid performance warnings, you will want to add a $bonemerge command to the character's QC file advising the game code that the bone will be used for bonemerges.

For more information on how to animate (world model) weapon attachments, see Animating Weapons

Attachment points

A list with all possible attachment points can you find here: