Attachment Positions

From The DarkMod Wiki
Jump to navigationJump to search

Originally written by Ishtvan:

See Attaching Props to AI for specific examples of props you can use in the editor.

Attachment positions define reference points and angles on AI (relative to joints) or non-animated entities (relative to the origin). These can be used to define general points that work for attaching a variety of objects. Each AI can have an offset from the general humanoid attachment points, and each entity can have an offset for each possible attachment position.

For example, suppose you attach a pouch to an AI's belt, referenced to a joint at the center of the hips. A fatter AI will have a belt that's farther away from the hips joint, so it will need an offset to the general attachment position. A fatter purse might need to be farther away from a belt to avoid clipping, so it could have an offset relative to the belt attachment position. The purse doesn't need to know what AI it's being attached to, it just knows it's being attached to some standardized point on the outside of an AI's belt. The AI handles the deviation from the standard AI, and the entity being attached handles the offset between its origin and the common attachment point.

Defining and Tweaking Attachment Positions and Attached Entities

The following is a guide to setting up attachment points and attaching objects to them. NOTE: This guide does not include AI-specific offsets to the common attachment points. I still have to test/document that.

1. Pick an item where you definitely know where the origin is, such as the rope arrow tip.

2. Def attach this (ammo_ropearrow_small) to a new attachment position:

"def_attach1" "ammo_ropearrow_small"
"pos_attach1" "new_position"

3. Define the new attachment position.

entityDef SomeAI
"attach_pos_name_newpos" "new_position"
"attach_pos_joint_newpos" "<if attaching to animated entity, joint we're attaching to>"
"attach_pos_origin_newpos" "0 0 0"
"attach_pos_angles_newpos" "0 0 0"

4. Tweak the position with the attach_pos_origin* spawnarg: First figure out how the joint is oriented and which way (x,y,z) becomes in world space. Dial it in to the position you want the origin of the thing you're attaching to be at, by looking at where the arrow tip is. This position should be very general, with the origin at the center of the palm or the top of the head or something, and shouldn't be pre-compensating for the origin of some oddball model (that's what entity-specific offsets are for).

5. Tweak the orientation with the attach_pos_angles* spawnarg: I'm not good at this... probably need the MD5 mesh in a 3d program where you can rotate stuff relative to the joint you're attaching and see what Euler angles it spits out. By hand, you can do some simple rotations like 90 degrees, 180 degrees, etc, but once you start trying to rotate about too many axes, things get screwy.

6. Now instead of a rope arrow, try attaching a specific model that is representative of the type of thing you'll likely want to attach to that position (for example, a sword in the hip sheath position). If it was modeled pointing a different direction than the rope arrow we're testing with, you'll have to take that into account and adjust the angles.

7. When you're satisfied that the orientation is what you want, and the attachment point is well defined on the AI, you can go to particular entities and add entity-specific offsets. These are translations and rotations relative to the attachment position and orientation you just defined, given by these spawnargs in the entityDef of the entity being attached:

entityDef EntityYouWantToAttach
"origin_[position name]" "0 0 0"
"angles_[position name]" "0 0 0"

The fastest way I've found to accomplish all this is to run the mod in windowed mode, edit the def files and use the console command "reloaddecls," after which you can spawn a new AI to see the changes you made in the def file. Important: Reloaddecls seems to have trouble with things that are inherited and changed on the base class. You may want to store things temporarily on the actual AI def you are spawning, then move it to the base class def once you're done.