Attachments

From Valve Developer Community
(Redirected from Attachment Points)
Jump to: navigation, search
English (en)Translate (Translate)

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.

Creating Attachment Points

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.pngNote: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. 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 the 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:

To see the attachments or bones of existing models, load the models using HLMV. Each has tabs in the viewer.

Mapping

To parent an entity to an attachment point, use the syntax parentname,attachmentname in the entity's Parent keyvalue. This maintains the entity's offset from the attachment point. Hammer doesn't recognize this syntax so it will appear as invalid, but it works in-game.

Additionally, two inputs exist to set attachment points. SetParentAttachment will attach the entity, and then teleport it to the position of the attachment point on the model. SetParentAttachmentMaintainOffset behaves the same, but won't teleport the entity to the attachment so the offset is maintained. Since the comma syntax already behaves this way, the only use this has is for dynamically changing attachment points after spawn.

See also