BF2.US bf2-rsdeveloper wiki Parity Discord bf2.us
On this page

Animation: triggers, bundles, the skeleton and the ragdoll

BF22142Heroes

A soldier's pose is not decoration. A bullet is tested against capsules on his bones, so where his arm is at the tick of a shot decides whether it is hit. The animation runtime therefore runs on the dedicated server too, and the port holds it to the original bit for bit: it is physics by another name.

From the soldier's movement to a posed skeleton the soldier's state direction in the camera's frame, speed, look, stance, and message bits (firing, reloading, zoomed) triggers a decision tree, evaluated every update from root and again from postRoot bundles the animations a trigger asked for, each with a time, a fade and a weight layers on the skeleton at most five a bone; a full-weight layer replaces what is under it sampling and blending two frames and a fraction; rotations on the sphere, positions in a line world matrices each bone times its parent: the capsules a bullet is tested against bf2_w32ded.exe!0x005bd420 (inputs), 0x00719e50 (update), 0x007206e0 (sample), 0x00716fc0 (blend), 0x0054dfb0 (hit pose)
From the soldier's movement to a posed skeleton. The upper half decides what plays; the lower half computes the bones.

An animation system is a script#

Each soldier template names two animation systems, one for first person and one for third (ObjectTemplate.animationSystem1P / animationSystem3P); weapons and seats name theirs. A system is a console script that builds three kinds of things (ModuleBoneAnimation::init, bf2_w32ded.exe!0x0070d53f):

ThingWhat it isScript object
animationone .baf file: for each bone a track of rotations and positions at 24 frames a secondanimationManager.*
bundleone or more animations that play together, with a length, fade-in (0.2 s) and fade-out (0.1 s), looping or not, and events (a footstep, a sound) at set timesanimationBundle.*
triggera node of a decision tree that picks bundles from the soldier's stateanimationTrigger.*

Animations are shared by every system of the process: a script that sets the length of a file sets it for all users, and the last one wins. At a level's load every system's script runs in name order, then every animation that some script named is loaded. The port runs every shipped animation script through its own interpreter and through the original's, with no error in either.

What a trigger sees#

Each frame the soldier hands its animation instance four things (updateAnimationSystems, 0x005bd420; setMovement, 0x00719380):

  • the direction of movement in the frame of his camera: side, up, forward;
  • the speed, horizontal; in first person scaled down when crouched or prone;
  • the look and turn input;
  • the pose: his stance, 0 to 3 (stances).

And messages: bits that say "firing", "reloading", "zoomed", "jumping", which the weapon and the soldier set or pulse for one update.

The direction does not jump. It blends toward the new one by dt x anim_smoothSet, and snaps only when the soldier was standing still or reverses. From the old and new velocity the instance also keeps a deceleration, which a trigger can ask for: that is how a soldier leans when he stops.

A change of pose runs a transition trigger by name: stillToProne when slow, else forwardToProne, backwardToProne, leftToProne, rightToProne by the direction; fromProne on the way up.

One update#

AnimationSystem::update (0x00719e50):

  1. the first time, the startup trigger runs;
  2. the tree is evaluated from root, then a second tree from postRoot (layers on top: the aim, the head);
  3. every playing bundle advances; one that ends is removed; a looping bundle that no trigger asked for again this update starts to fade out. A trigger must want a looping bundle every update to keep it;
  4. an idle clock runs while exactly one bundle plays, so that an idle trigger can start a fidget after some seconds.

Idle fidgets and the head's idle turn draw from the C runtime's random number, shared by the whole process. On the server this stream is part of the state that must match: the port's draws equal the original's in 696 of 696 on a ladder run and 68 of 68 in a hit test run.

Onto the skeleton#

A bundle pushes layers to the skeleton: (animation, time, weight). Skeleton::updateFromAnimations then computes each bone:

  1. Sampling (BoneAnimation::sample, 0x007206e0): the time picks two frames and a fraction; rotations are interpolated on the sphere (Quaternion::slerp, 0x0068d630), positions in a line.
  2. Distribution (0x00716f30): a layer goes to every bone its animation has a track for. A bone keeps at most five layers; a layer of weight 1 discards the ones before it.
  3. Blending (0x00716fc0): the first layer replaces, the others blend in by their weight.
  4. World matrices: each bone's local transform times its parent's.

The skeleton is persistent: a bone that no layer reaches keeps the transform it had. That is what a dead soldier's body relies on: the body bundles end and the pose stays.

The aim#

In third person the upper body follows the camera (0x005bdcc0): a pitch and a yaw are taken from the angle between the soldier's frame and his camera's forward direction, and applied over the animated pose. Swimming gives pitch 0. The head adds an idle turn: it holds, picks a target a little to one side, and moves there at a speed proportional to the distance.

In first person the camera sits on a spring instead (updateFirstPersonAnimations, BF2.exe!0x0061d8a0), so the weapon lags and settles when the view turns. Arms that must hold a weapon in two places are solved by inverse kinematics.

Why the server animates#

Soldier::getSkeleton3PForPose (0x0054dfb0) is called by the collision code: the soldier's collision response, the projectile pass and the projectile's collision components. On the host, once per tick per soldier, it evaluates the third-person skeleton with a step of 1/30 s; the capsules on its bones (setSkeletonCollisionBone) are what a bullet is tested against. For a remote player the server first rewinds by his measured ping, so that the shooter hits what he saw (lag compensation).

The ragdoll#

When a soldier goes down outside a vehicle, his body becomes a ragdoll (RagDoll.cpp, update 0x0070b690): 13 particles on chosen bones, held together by 18 distance constraints, 12 angular and 4 dihedral ones, with 12 capsules for the limbs. It steps at a fixed 1/90 s from an accumulator: gravity, forces, a Verlet step, the constraints, collisions against objects and the terrain, then a sleep test. Its start velocity is the soldier's at the moment of death, so a soldier shot while running keeps his motion. The ragdoll's particles then drive the skeleton's bones.

What the port has#

The notes' status, which is unusually complete for this subsystem:

PartCheck
sampling, slerp139,176 cases a precision against the original functions, the same bits
bundle playback, layers20,000 random bundles and states a precision
trigger evaluation, the instance's update10,000 random trigger trees a precision
the skeleton's pose1,200 skeleton updates on the shipped skeletons and animations
arm IK, the ragdoll and its bone driver, the death cameraverified against the original functions
the soldier's inputs, the first-person springverified
server poses, moving, crouched and prone606 of 606 hit-test skeletons identical to the original server's
the soldier's aimimplemented from the instructions; the function itself is not run against the original
seated soldiersimplemented; one seated target compared with the original server

How it is tested#

  • Oracle tests: the original's matrix and quaternion primitives, skeleton poses, trigger trees, bundle playback and sampler are run in a process of its own on a list of inputs, and the port must give the same output bit for bit (the oracle) (crates/bf2-anim/tests/oracle.rs); a second program does the same for the soldier's animation update and the first person spring (soldier_oracle.rs).
  • The aim (crates/bf2-anim/tests/aim.rs): look limits per game, the quarter of the pitch and third of the yaw the extra transforms take. Its expectations are derived from the instruction sequence, not produced by running the original: the page's table says so.
  • On the server (crates/bf2-server/src/damage_anim.rs): the skeleton evaluated for hit detection, the ragdoll's variables.

Ten of twelve addresses stand in a test.

In the code#

WhatWhere
the runtimecrates/bf2-anim (sample, system, system::script, system::runtime, pose, aim, soldier, first_person, ik, ragdoll)
the server's soldier posescrates/bf2-server/src/damage_anim.rs
the file formatsanimation files

Notes: notes/subsystems/animation.md, notes/formats/animation.md.

Source: docs/dev/soldier/animation.md · built from bf2-rs e3b4f05 · part of the Battlefield 2 / 2142 / Heroes reimplementation. Not affiliated with EA or DICE.