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

Seats and cameras: entering, switching, leaving, and what you see

BF22142Heroes

A vehicle is a tree of objects, and some of its nodes are player control objects: seats. A seat is what a player controls while he sits in it: it takes his input, owns its weapons, and has cameras as children. This page follows the use key from the soldier into a seat and out again, and then the camera that shows it.

The use key, on the server guards not while down or dead; not within 1.0 s of the last enter or exit in a vehicle: leave an exit position must be free; the soldier keeps the vehicle's speed x exitSpeedMod on foot: the entry search entry points within 3 m: not a wreck, own team or none, a free line; the nearest wins at the vehicle: a seat the first free seat in position order; a seat held by a bot can be taken else: ropes and ladders a zipline, then every ladder bf2_w32ded.exe!0x00456b50 (the handler), 0x0057ff00 (the entry search), 0x00458cd2 (seat keys F1 to F8), 0x00594c10 (abandoned)
The use key on the server. A press does one of three things, and never two within a second.

A seat#

PlayerControlObject (template bf2_w32ded.exe!0x00597f10). The root of a vehicle is one (the driver's); further seats are children with their own position id. What a seat's template says:

PropertyDefaultMeaning
vehicleCategory, controlsCategorywhich control map the player gets: land, sea, air, helicopter
dontAllowExit, hasRestrictedExit0a seat one cannot leave, or only by a rule
exitSpeedMod1.0how much of the vehicle's speed the leaving soldier keeps
isOpenVehicle0the occupant can be shot
allowDucking0the occupant can duck into the hull
sprintFactor, sprintLimit, sprintRecoverTime2.5, 0, 0the boost (a jeep's sprint key)
crewKitIndex-1a kit the seat requires
damageForBeingOutSideWorld999999what leaving the map costs

The seat hands the player's input to its occupant, then to each of its weapons, then to its own parts (0x00595dc0). A seated soldier is still there: he is posed in the seat, can be hit when the vehicle is open, and is the one who dies.

The use key#

The server's input processor calls the handler (0x00456b50) when the use key is down. In order:

  1. Nothing when the soldier is down or dead, or when less than 1.0 second has passed since his last enter or exit.
  2. In a vehicle: leave. The exit position is computed; when none is free the player gets a message and stays. On leaving, the soldier's velocity becomes the vehicle's times exitSpeedMod (times 0.7 for seats of a subclass). A soldier who leaves a fast vehicle leaves at its speed.
  3. On foot: look for a seat within 3.0 m (5.0 m when the game itself seats a player at a spawn). Only a standing soldier may.
  4. Still nothing: ropes and ladders. A soldier tries a zipline and then every ladder.

The entry search#

0x0057ff00 asks the world for entry points around the soldier and takes the nearest whose vehicle qualifies:

  • within the radius, or within the entry point's own entryRadius (default 3);
  • the vehicle is not a wreck;
  • its team is the player's or none (a vehicle that carries the other team's number cannot be entered);
  • the line from the soldier to the entry point is free; other soldiers do not block it;
  • of two candidates at exactly the same distance, the later one wins.

At the vehicle, the first free seat in position order is taken. A seat held by a bot can be taken by a human: the bot is moved on.

Switching seats#

F1 to F8 ask for a position (0x00458cd2 on). The lowest key wins when several are down.

CaseResult
the same seat, or the current weapon cannot be put away (it is firing or reloading)refused
the seat is freeexit and enter at once: the one-second delay does not apply
the seat is held by a humanrefused, with a message
the seat is held by a botthe two swap: the bot takes the player's old seat

An abandoned vehicle#

A vehicle left away from its spawner destroys itself (0x00594c10). The check runs every 5 seconds while all is well and every half second while it counts down:

  1. somebody sits in it: nothing;
  2. it is within its spawner's distance (50 m by default): the countdown is reset;
  3. a living soldier stands within three times its explosion radius: the countdown pauses. So a vehicle never starts to burn beside somebody who could be killed by it;
  4. else the countdown runs; at zero the vehicle takes damageWhenLost every second.

Cameras#

A Camera (template 0x005a3210) is a child of a seat, and is itself a rotational bundle: looking around in a seat turns the camera object within its limits, like a turret. One seat can have several.

View modeWhat it showsAllowed by
Insidethe camera's own place, or the seat's, with shake and swaythe template (CVMInside, on by default)
Nosethe camera moved by nosePosthe template and the server setting sv.allowNoseCam
Chasebehind and above the vehiclethe template and sv.allowExternalViews
FrontChasethe same from the frontthe same
FlyBya point ahead of the vehicle that it then passesthe same
Trace, ExternTracea following camera with a bufferthe template; off by default

The camera key cycles through the modes and skips those that are refused (0x004db090). A server that turns external views off thereby turns the cycle into "inside only". The field of view is insideFOV inside and worldFOV otherwise (both 1.2 by default).

The chase camera#

0x005a2b40, each frame:

text
point     = the vehicle's position (or chaseOffset in the vehicle's frame)
distance  = chaseDistance,  or  2 x max(the vehicle's bounding radius, 2)  when it is -1
target    = normalize(chaseAngle x up - forward)             (+ forward for the front chase)
k         = clamp(followStiffness x dt, 0, 1)
direction = slerp(direction, target, k);   distance likewise
eye       = point + direction x distance,  lifted to at least 1 m above the terrain and the water
look from the eye at the point

followStiffness is why a chase camera lags in a turn and catches up. The automatic distance uses the vehicle's physics bounding radius: the collision mesh plus every child with its offset, so a tank with its turret and barrel counted stands farther from the camera than its hull alone would put it.

All the view modes, side by side#

The piece below puts the camera where each mode puts it. Set the bounding radius to a tank's (6.3 m for the T-90 with its turret and barrel, by the notes) or a large walker's (13.3 m) and watch the automatic chase distance follow it; most player seats of Battlefield 2 set chaseDistance themselves (17 m for the T-90).

The last mode of the piece is not this class's: after a death the player's free camera is put into a follow mode on what he controlled (GameLogic::killPlayer, bf2_w32ded.exe!0x004659f0; FreeCamera::setViewMode, 0x005f5450). It orbits at three times that thing's bounding radius, at least 3 m, turns toward its offset with a blend like the chase camera's, keeps its eye above the ground and looks at the followed thing. From which side the orbit starts is not in the notes, so the piece's direction there is its own.

A soldier on foot does not use the vehicle camera either: his first person eye comes from the soldier template's poseCameraPosition lines, one per stance. The constructor's defaults are zero, and 0.3 m for swimming; the shipped values are the game's data and are not in the notes, so no piece draws them. Heroes' seated look is on Heroes' vehicles.

Free look#

With the mouse-look key held (or always, for a camera without toggleMouseLook) the camera turns as a rotational bundle. Released, its rotation is multiplied by 0.75 every tick: it springs back to straight ahead in about a third of a second (0x005a3530).

2142
Battlefield 2142 and Heroes

The same classes. 2142's walkers use the same bounding radius rule for their chase distance (13.3 m traced for the large walker). Heroes' seats add the ducking rules listed on widgets.

What the port has#

PartState
the use handler, the entry search, the exit position and speedverified, the same bits
seat switching and the swap with a botverified; seen in the same order as on the original server
abandoned vehiclesverified: 514 of 514 armor events of a recorded run
chase and front chase, the view mode setter and cycle, the keys, the field of view, the nose viewverified
which of several cameras a seat uses; the cockpit's sub-geometryread as a draft; not traced to the end
shake, sway and bouncenot reproduced

How it is tested#

  • Oracle tests: the original's entry search, abandon check, rotational input and ladder input 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-gameplay/tests/it_bf2/vehicle_oracle.rs, 26 cases).
  • The chase camera is marked verified in the camera notes against the original's function and its helpers; the death orbit has statement tests on the server (crates/bf2-server/src/players.rs, players_input.rs).
  • Scenarios play seats: each seat's camera asserted from the client's trace, seat keys, a seated look turned to its stops.

Not reproduced, and so not tested: shake, sway and bounce. Which of several cameras a seat uses is read as a draft.

In the code#

WhatWhere
use, entry, exit, seat switch, abandoncrates/bf2-gameplay/src/vehicle/ (use_flow, entry, exit, seat_switch, abandon)
camerascrates/bf2-gameplay/src/camera/ (chase, view)
the server's sidecrates/bf2-server/src/vehicles_use.rs, vehicles_abandon.rs
seated soldiers' poseanimation

Notes: notes/subsystems/gameplay-vehicles.md (sections 5 and 6), notes/subsystems/gameplay-cameras.md.

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