Procedural Weapon Animations

Overview

Procedural Weapon Animations aim to reduce the amount of animation assets needed to animate the weapons, provide more flexibility for designers to tweak the look and feel of the weapons, reduce memory budgets, reduce processing budgets and simplify weapon production while still delivering competitive visual quality.

How does it work?

The first person weapon hands have a special bone called the weapon target. When right hand IK solution is activated, the right arm will move in order to align the right hand to this target. Since the weapon is by default attached to the right hand, this will also move the weapon in screen space as well. The left hand IK solution is also activated at the same time and making the left arm follow the movement of the weapon. The base pose asset will place this weapon target on a neutral position to place the weapon on the screen.

The code can then manipulate the position of this target by adding an offset (Procedural Weapon Offset) and therefore moving the weapon on the screen without the need of additional animation assets. The offset has 6 degrees of freedom (6DOF), translation in XYZ and rotation on XYZ as well. In Crysis 2, every movement to the weapon had to be done through additive animation assets; the game had hundreds of those assets.

It is possible to also add a 6DOF offset to the left hand. This way, it is possible to realign the left hand to the bottom of an under barrel attachment.

First Person Animation Pipeline

The CryENGINE animation engine supports up to 16 layers of animation. Each layer can play a single animation asset (or a transition from one asset to another for smooth transitions) and each asset can animate a specific set of bones on the character. By default, an asset will override the bone animation from the underling layer unless the asset is specified to be additive which will add an offset instead. In between each animation layer, any amount of "Pose Modifier" can be installed. Pose Modifiers are code algorithms that can procedurally manipulate the bone structure. Those Pose Modifiers can be accelerated by the SPU's for PS3.

Crysis 2 First Person Animation Pipeline

The first layer have a base pose animation asset. This is a single frame animation that will place all the bones of the arms in the right place. A different base pose is needed for each zoom mode that weapon supports. The layers on top have different additive animations that manipulate the weapon position in a particular way, move and rotation sways, idle, run or sprint animations, etc, were all implemented that way. A Pose Modifier is applied on top of all this layer; STAP Pose Modifier. This Pose Modifier is responsible to rotate the entire body above the spine around the camera position. This way the arms rotate in the direction of the camera view without rotating the legs. The arms and legs in first person are the same model. Lastly, action additive animation assets are played on top if needed; those actions include melees, reloads, recoils, etc.

By using ca_debugText 1 it is possible to see the full animation pipeline.

Layer 0 has the base pose, layers 2 to 7 have additives assets that play all the time on the weapon and layer 9 is playing an action additive animation, in this case, a reload animation. Layer 1 is reserved for the Base Pose Modifier, a special asset that moves the left hand down when using under-barrel attachments. Layer 8 is reserved for the Bump and Jump Assets. In total, up to 10 layers can play at the same time. The STAP Pose Modifier is set between layer 5 and 6 and can be changed with the CVar g_stapLayer.

Crysis 3 First Person Animation Pipeline

The first layer have the base pose asset like in Crysis 2 but this time the weapon target bone is also placed in the right position. The following layers (so far only 1 was needed) plays the semi-procedural animation assets (more of that in a minute). And Then the STAP Pose Modifier is applied and right after the Weapon Offset Pose Modifier (implemented using the COperatorQueue class) is executed. After that the additive action animation assets are played. In the end, the IK solution is executed to re-target the hands to their final places.

Layer 0 still plays the idle pose, layer 1 plays the semi-procedural weapon animation and layer 9 is playing a reload animation. Please note that it is not needed to have specific animation assets for the different zoom modes of the weapon.

Semi-Procedural Weapon Animations

As explained before, by just offsetting the weapon target bone it is possible to play any kind of procedural animations on the weapon due to the IK solution. While in most of the cases this offset is going to be provided with specific code implementation, in some cases it is still preferable that animators provide the animation. That is the case for the idle, run and sprint animations. However, contrary to Crysis 2, in Crysis 3 only the weapon target bone needs to be animated, the IK solution does the rest. For this reason, the same asset can be used for different zoom modes and probably for different weapons as well. The current implementation also supports to change the playback velocity and intensity depending on the weapon being equipped, player speed, zoom state and fire mode selected.

Procedural Animation Features

Weapon Zoom Modes

This feature implements the transitions from shoulder poses to the weapon zoom mode (ironsight, reflex, assets, etc). Both shoulder and zoom stages have a predefined 6DOF offset. The transition from one offset to another is done using a smooth curve (based on Hermite cubic interpolation).

Look and Strafe Offsets (Weapon Sway)

Like on Crysis 2, Weapon Sway interprets the movement of the player and camera rotation into weapon movement.

Procedural Recoil

In Crysis 2, the third person characters had procedural recoil. In Crysis 3, both first and third person characters will have procedural recoil. Right now, the algorithms that drive those recoils are not the same. In the future, first and third person will share the same recoil implementation.

Left Hand Offset for Under Barrel Attachments

When attaching an under barrel accessory, the left hand will suffer an offset so the hand correctly touches the bottom of the accessory instead of clipping through it.

Smooth Shoulder Offset Transitions

A smooth transition from different shoulder offsets are possible. This allows to switch from normal shoulder pose to altered shoulder poses for special fire modes, weapon modifier menu pose, cinematic lower pose and friendly fire lower pose.

Weapon Customization Menu

This will offset both right and left hand to create the pose used by the weapon customization menu. Each weapon can define it's own position.

Bump Animation

When the player falls from an height or from a jump, a simple bump animation will play depending on the landing velocity.

Custom Offset

For very specific situations, any arbitrary offset can be added. As an example, the current Bow weapon implementation uses a custom offset to implement the hand shaking when the bow is charged for too long.

Missing Features and Known Bugs

Transition from run to sprint is still too sharp, can be much improved.

Weapon XML Setup

For a quick example, check rifle.xml. This is the SDK rifle using the Procedural Weapon Animation.

Both Crysis 2 and Crysis 3 implementations are presented on the current builds. By default, due to retro-compatibility, the Crysis 2 is the selected one. To enable the Crysis 3 implementation, add this command to the weapon parameters:

<param name="proceduralSway" value="1" />

For this weapon, Crysis 3 implementation is now enabled and Crysis 2 implementation is partially disabled (sliding still goes through the Crysis 2 code path, check Known Bugs section).

AnimAnims only need 4 assets now:

<aimAnims>
  <param name="base" value="stand_tac_idlePose_scar_proto_shoulder_1p_01" />
  <param name="idle" value="stand_tac_idle_scar_proto_shoulder_add_1p_01" />
  <param name="run" value="stand_tac_run_scar_proto_shoulder_add_1p_01" />
  <param name="sprint" value="stand_tac_sprint_scar_proto_fwd_add_1p_01" />
</aimAnims>

Please note the absence of [suffix], only shoulder versions are needed.

To Specify the shoulder 6DOF offsets, add this to the weapon params:

<aimLookParams>
  <param name="fp_offset" value="0.015,-0.0,-0.03" />
  <param name="fp_rot_offset" value="0.0,-0.2,-0.5" />
</aimLookParams>

Rotation are specified in Euler XYZ and in degrees.

For each fire mode, new parameters were added to control the procedural recoil:

<proceduralrecoil>
  <param name="duration" value="0.4" />
  <param name="strength" value="0.06" />
  <param name="kickIn" value="0.3" />
  <param name="dampStrength" value="7.5f" />
  <param name="fireRecoilTime" value="0.05f" />
  <param name="fireRecoilStrengthFirst" value="3.0f" />
  <param name="fireRecoilStrength" value="0.5f" />
  <param name="angleRecoilStrength" value="0.4f" />
  <param name="randomness" value="0.1f" />
</proceduralrecoil>

The first 3 values came from Crysis 2 and control the third person procedural recoil. The other values are new and are for the first person. In the future, they should be intergrated to only one interface for both first and third person. The procedural recoil uses an identical mechanism found on car's suspensions. A spring keeps the weapon as close to the neutral point as much as possible and a damp filters quick movements. "dampStrength" controls the strength of that damp effect, "fireRecoilTime" specifies for how long a recoil force should be applied, "fireRecoilStrength" specifies how strong the recoil is, "fireRecoilStrengthFirst" does the same but is only applied for the first shot in a rapid fire of burst fire modes, "angleRecoilStrength" will specify the maximum deviation angle the recoil can have and finally "randomness" provides a more organic feeling to the recoil implementation.

Zoom modes also have additional parameters:

<zoom>
  <param name="fp_offset2" value="-0.0535, \-0.08, \-0.012" />
  <param name="fp_rot_offset2" value="0.0, 0.0, 0.0" />

Those parameters specify the 6DOF Offset for that specific zoom mode. Since Crysis 2 also supported offsets (implemented in a different way), the name of the parameters include a '2' to avoid conflicts.

Weapon Offset Tool

Interface

The Weapon Offset Tool was developed to help designers and animators to tweak weapon positioning in the screen and to create 6DOF Offsets to be used on the XMLs.

g_debugWeaponOffset 1

The game plays normally but with an overlay of some guide lines. The White lines are simple diagonals that can help to place the weapon in the right place. They are perfect 45 degree diagonals and cross exactly in the middle of the screen. The black lines are placed in the crosshair position and have ruler like lines: especially useful while creating zoom modes. The green line goes from the weapon term (a helper point representing the exit of the barrel) towards the infinite (not quite, 1 kilometer is big enough to be considered infinite).

Please note that the green line does not meet the center of the screen. One of the issues faced during Crysis 2 production was that it was quite hard to properly align the weapons. The Scar was the best aligned weapon and still is quite far away from the center of the screen.

We can fix that with the help of this CVar: g_debugWeaponOffset 2

After enabling this CVar, the weapon stops animating and the game inputs stops working. Additional information appears on the screen. The game is now in Weapon Offset Tool Edit Mode. The pose the weapon has right now is the unmodified pose provided the the animators, 100% Base Pose Asset. Please notice that even in this mode, the green line still does not align with the center of the screen, that should be the first thing to do.

While holding mouse left click and moving the cursor, the weapon will start moving in the X and Z axis. With the right mouse, the weapon rotates on the X and Z axis. The middle will both tilt the weapon if the cursor moves horizontally and approximate the weapon if the cursor moves vertically. Use the 1, 2, 3 buttons on the keyboard (not numpad) to change the sensibility of the movements.

Interesting fact: while using the right mouse mode to rotate the weapon, you can perfectly align the barrel to the center of the screen. Using the other 2 modes after that will not change that alignment and therefore it turns out it is quite easy to guaranty perfect alignment all the time. This is because rotating the weapon on X and Z axis are the only way to change the parallelism property of the weapon to the view. After the weapon and the view direction are perfectly parallel, translations on XYZ and rotations on Y cannot destroy this property.

A properly aligned shoulder pose:

A properly aligned ironsight (please note that the green line lies perfectly on the vertical black line):

By pressing the Q button on the keyboard, the offset editor switches to left hand offset editor. All commands will affect the left hand instead of the right hand. By pressing the E button on the keyboard, the right hand is re-selected. Use this to create left hand offsets while using an under barrel accessory or to create a weapon modifier menu pose.

Input and Output CVars

After the 6DOF Offset is successfully placed, this CVar should be called to export the values calculated: g_weaponOffsetOutput

This CVar will output the following to the console (and therefore to the editor.log or game.log):

<15:02:28> \[CONSOLE\] Executing console command 'g_weaponOffsetOutput '
<15:02:28>    Recover: \-0.058213 \-0.104529 \-0.013025 0.018817 0.023134 0.000353
<15:02:28>    Position: "-0.058213, \-0.104529, \-0.013025"
<15:02:28>    Angles: "1.078160, 1.325502, 0.020216"

'Position' can be copy-pasted directly to the XML parameter "fp_offset". 'Angles' can also be copy-pasted into "fp_rot_offset". Both right and left hand offsets will be outputted. 'Recover' is used to recover old offset into the tool for further improvement of the offset (only right hand is supported at the moment). It is done in this way:

g_weaponOffsetInput -0.058213 -0.104529 -0.013025 0.018817 0.023134 0.000353

And the weapon will jump to that position. The first 3 numbers are the translation, the 3 last numbers are the angles and radians. In the future, 'fp_offset' and 'fp_rot_offset' should be totally substituted into 'fp_6dof_offset' that accepts that format. While harder to use by hand, it becomes much more efficient to use with the tool.

The g_weaponOffsetReset console command will just reset all offset values back to 0.

Sending Weapon Alignment to Mannequin

When in the Sandbox Editor a weapon's alignment can be sent directly to mannequin during it's setup. Some specific procedural clips are required however.

The mannequin procedural clip WeaponPose must be added to the idlepose of the weapon.

Select the ProcLayer.

As mentioned earlier use g_debugWeaponOffset 2 to align the weapon to the desired location.

Once the alignment is set enter the console command: g_weaponOffsetToMannequin.

This will send the current alignment of the weapon directly to the clip.

The Guide Lines

Each line on the screen has a specific meaning. The golden lines and split the screen line a grid are the golden ratio lines and should help to place the weapon in interesting positions. The 2 crossing lines, light gold, further helps on that.2 Black lines can be found on the center of the screen (not very visible on this picture but they are there) help to align the weapon to the cross hair. The 3 green lime lines should be used to align the ironsight dots, the red circle is for the reflex sight alignment, the inner blue circle for the assault scope and the outer blue line for the sniper scope.

The golden ratio lines are always on an aspect ratio of 16:9 (HDTV). The green line coming out of the weapon comes out from the weapon_term helper and follows the Y axis of that bone until infinity; this line should always be aligned to the center of the screen in shoulder and zoom poses (especially for weapons that use laser sights). Obeying those guide line is highly advised to have a consistent behavior across weapons.