Blend sequence

From Valve Developer Community
Jump to: navigation, search
A blend sequence altering the yaw of an NPC's aim. A second blend sequence will be needed to control pitch.
HLMV's 'Sequence' tab can control blends. This character is running backwards and aiming slightly upwards.

A Blend sequence is a $sequence that can move smoothly between $animations based on one or two sliding 'blend scale' values. This allows the animation's state to be easily controlled by code.

Walking and aiming direction are almost always determined by blend sequences.

Creating blend sequences

The ideal number of animations in a blend sequence depends on how precise the motion needs to be, and on how much variation there is to be along the blend scale(s). Valve use nine for their walking blends (see the example below). With blends that produce a still pose rather than an animation you can get away with one for each extreme, but may find it easier to work with a third, central animation for the zero position.

Once you have your animations, simply list them within the sequence's keyvalue block in the desired order. They will be evenly distributed along the blend scale.

blend <string name> <float min> <float max>
Defines a blend controller. If blendwidth is defined the first controller moves up/down through the blend, and the second (if present) left/right.
blendwidth <int width>
How many columns of animations the blend contains. The number of rows is determined automatically.
blendcenter <string sequence>
Defines the sequence to be used in the center of the blend. (0 0) This can be any sequence in the blend.
blendref <string sequence>
Defines the sequence to be used to align the blend. This can be any sequence in the blend.
calcblend <string name> <string attachment> <XR YR ZR>
Allows the compiler to determine the range of a blend based on the rotation of a predefined attachment point. The resulting angle ranges will be based on the attachment point's orientation rather than the bone its parented to.

Blend Example

This example creates a 9-way walking blend, suitable for use with CBasePlayerAnimState. Earlier Valve games use 8-way blends; check whether your game's existing models have move_x/move_y (9-way) or move_yaw (8-way) to determine which you should create. See the SDK sample HL2 models for an 8-way example.

// Define all nine walk_* $animations above this command (use walkframe!)

$sequence walk {
	walk_SW   walk_S   walk_SE
	walk_W    walk_C   walk_E
	walk_NW   walk_N   walk_NE // line breaks are for readability only

	blendwidth 3
 	blend move_x -1 1
 	blend move_y -1 1

	addlayer look // blends look/aim direction on top of walk direction

Calcblend Example

This example creates a 9-way look blend delta sequence. using the calcblend

// Define all nine look_* $animations above this command with subtract

$sequence look {
	lookDR	lookD   lookDL 
	lookR    "anims\referencepose.smd"   lookL
	lookUR   lookU   lookUL
	blendwidth 3
 	calcblend head_yaw "anim_attachment_head" YR  
 	calcblend head_pitch "anim_attachment_head" ZR

The output value for the blend slider ranges now should be based on the relative rotation of the defined attachment.

Animating for blend sequences

There is nothing particularly special about the individual animations which make up a blend sequence. However:

  • It is important that each animation is the same length and plays at the same framerate
  • Use walkframe if the animation is intended for movement
  • In your modelling package, make sure that any root bone keyframes are set to linear interpolation (i.e. a straight line) to avoid velocity "wobble" when looping
  • To ensure velocity matches animation 1:1 consider the total frames of an animation. For instance an 18 frame run cycle that moves 200 units will result in speed of 333.33

See also