The soldier: input, stances and sprint
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:
- Timers. Unless this is a replay (
flags & 4), two timers count down bydt. - In a vehicle the soldier takes the input only when the seat lets him; no movement input is used.
- Look. The mouse axes times the sensitivity, with a dead zone of 0.001.
- 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. - Jump is cancelled in water. Crouched or prone it does not jump but still counts for the weapon's deviation.
- Yaw is added up with wrapping at 360 degrees and the seat's limits.
- A jump on the ground gives an impulse along the ground's normal, costs
sprintLossAtJumpstamina and sets the sprint's recovery delay. - Movement and stance requests (
0x0054f800,0x0054fbb0,0x0054f200). - 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):
| Field | Offset | From the template | Start value |
|---|---|---|---|
| dissipation time: seconds from full to empty | +0x00 | +0x294 | 0 |
| recover time: seconds from empty to full | +0x04 | +0x290 | 0 |
| limit: stamina needed to start | +0x08 | +0x298 | 0 |
| dissipation factor | +0x0c | 1.0 | |
| stamina | +0x10 | 1.0 | |
| requested (cleared every update) | +0x14 | 0 | |
| sprinting | +0x16 | 0 |
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 = falseThings 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#
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 accelerationevery tick: fast at first, slower toward full speed;- a throttle below 0.001 snaps to 0 (
0x00725faf); - the speed (
0x007219ca,0x0071d0d0) is multiplied bysoldierSpeedFactor, 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 movementand 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):
| Crate | What it is |
|---|---|
crates/bf2-gameplay | the behaviour of gameplay objects: weapons, projectiles, soldiers, vehicles |
crates/bf2-physics | physics: collision queries, materials, rigid-body integration |
Files this page names: crates/bf2-gameplay/src/soldier/sprint.rs, crates/bf2-physics/src/soldier.rs.
docs/dev/soldier/movement.md · built from bf2-rs e3b4f05 · part of the Battlefield 2 / 2142 / Heroes reimplementation. Not affiliated with EA or DICE.