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

The soldier: input, stances and sprint

BF22142Heroes

A soldier is the player's control object on foot. Once a tick it takes the player's action, turns it into a look direction, a movement request and a stance, and hands the rest to its weapon. The same code runs on the server and, for the player's own soldier, on the client.

One tick of input#

Soldier::handlePlayerInput (bf2_w32ded.exe!0x00551150), in the order it works:

  1. Timers. Unless this is a replay (flags & 4), two timers count down by dt.
  2. In a vehicle the soldier takes the input only when the seat lets him; no movement input is used.
  3. Look. The mouse axes times the sensitivity, with a dead zone of 0.001.
  4. Move. Strafe and throttle are clamped to [-1, 1] and squared with their sign (sign(x) x x^2, dead zone 0.001): half a stick is a quarter of the speed.
  5. Jump is cancelled in water. Crouched or prone it does not jump but still counts for the weapon's deviation.
  6. Yaw is added up with wrapping at 360 degrees and the seat's limits.
  7. A jump on the ground gives an impulse along the ground's normal, costs sprintLossAtJump stamina and sets the sprint's recovery delay.
  8. Movement and stance requests (0x0054f800, 0x0054fbb0, 0x0054f200).
  9. The weapon gets the input and a trigger for its deviation: jump || (!inVehicle && lie).

The soldier's own physics (the capsule against the world, ladders, zip lines, the grappling hook of 2142) then runs in the tick's physics stages, at the player's turn (the frame and the tick).

Sprint#

The Sprint helper sits in the soldier at +0x334; the same 0x18-byte helper is a vehicle's boost. Its update, 0x0061ab90(blocked, recoveryDelay, dt):

Sprint::update(blocked, recoveryDelay, dt) bf2_w32ded.exe!0x0061ab90 not sprinting stamina += dt / recoverTime (to 1) only while recoveryDelay <= 0 recoverTime <= 0: stamina = 1 at once sprinting stamina -= f / dissipationTime x dt f = factor x (0.5 on an infantry-only server) never below 0 requested, stamina >= limit, start (event 0x2a) not blocked not requested, or stamina 0, or blocked: stop (0x2b) blocked = weapon zoomed, in a vehicle, crouching or prone, or dissipationTime is zero a jump costs sprintLossAtJump and sets recoveryDelay; a start drains from the next tick on
The sprint helper. Stamina runs from 0 to 1; the template gives the seconds to drain and to recover.
FieldOffsetFrom the templateStart value
dissipation time: seconds from full to empty+0x00+0x2940
recover time: seconds from empty to full+0x04+0x2900
limit: stamina needed to start+0x08+0x2980
dissipation factor+0x0c1.0
stamina+0x101.0
requested (cleared every update)+0x140
sprinting+0x160
Sprint::update, as the original has it
blocked |= dissipationTime <= FLT_EPSILON
not sprinting:
  recoverTime <= 0            -> stamina = 1
  else if recoveryDelay <= 0  -> stamina = min(stamina + dt / recoverTime, 1)
  requested && stamina >= limit && !blocked -> sprinting          (event 0x2a)
sprinting:
  f = factor * (sv.noVehicles ? 0.5 : 1)
  stamina = max(stamina - f / dissipationTime * dt, 0)
  !requested || stamina <= 0 || blocked -> stop                   (event 0x2b)
requested = false

Things the listing says that a player may not have known:

  • An infantry-only server drains sprint at half the rate. sv.noVehicles (forced off in co-op) halves the factor.
  • A sprint cannot start while the weapon is zoomed, in a vehicle, crouching or prone.
  • A jump costs stamina at once and delays the recovery.
  • The start takes a tick: the update that starts a sprint does not drain yet.

Ours: crates/bf2-gameplay/src/soldier/sprint.rs; the soldier's update that feeds it is 0x00552b20.

Heroes' hero#

Heroes
Battlefield Heroes

A hero's movement was audited value by value against the 1.126 data and code: 90 rows, 90 equal. The values come from the SoldierTemplate constructor (BFHeroes.exe@bfh126!0x0075dbc9, +0x440..+0x4a0) and the hero tweak files. The run-up is its own formula in the movement step (0x00721ba7):

  • throttle += (1 - throttle) x acceleration every tick: fast at first, slower toward full speed;
  • a throttle below 0.001 snaps to 0 (0x00725faf);
  • the speed (0x007219ca, 0x0071d0d0) is multiplied by soldierSpeedFactor, the door for everything that makes a hero faster or slower (abilities).

Heroes' soldier physics has 2142's layout, not Battlefield 2's: the on-ground test and the state bytes sit where 2142 has them. The three classes differ in hit points: Commando 80, Soldier 110, Gunner 150.

How it is tested#

  • The soldier movement differential replays recorded input through our server and compares positions with the original dedicated server's captures (543 and 776 ticks), in the fast gate whenever the server's simulation changed.
  • The player action sweep runs 519 cases side by side with the original server.
  • Heroes: tools/bfheroes/parity_audit.py --system movement and the scenarios with a walking hero.

Notes: notes/subsystems/gameplay-soldier.md, notes/subsystems/physics-soldier.md, notes/bfheroes/parity.md. Code: crates/bf2-physics/src/soldier.rs, soldier_control.rs, soldier_ladder.rs, soldier_zipline.rs.

More of the soldier: stances and states, animation, kits and supplies. Where the input comes from, keys and mouse to the 64 values: input and controls.

In the code#

The crates this page names, each with its line of docs/release/LAYOUT.md (the list is gathered by the wiki's build from the page itself):

CrateWhat it is
crates/bf2-gameplaythe behaviour of gameplay objects: weapons, projectiles, soldiers, vehicles
crates/bf2-physicsphysics: collision queries, materials, rigid-body integration

Files this page names: crates/bf2-gameplay/src/soldier/sprint.rs, crates/bf2-physics/src/soldier.rs.

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