On this page
Seats and cameras: entering, switching, leaving, and what you see
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.
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:
| Property | Default | Meaning |
|---|---|---|
vehicleCategory, controlsCategory | which control map the player gets: land, sea, air, helicopter | |
dontAllowExit, hasRestrictedExit | 0 | a seat one cannot leave, or only by a rule |
exitSpeedMod | 1.0 | how much of the vehicle's speed the leaving soldier keeps |
isOpenVehicle | 0 | the occupant can be shot |
allowDucking | 0 | the occupant can duck into the hull |
sprintFactor, sprintLimit, sprintRecoverTime | 2.5, 0, 0 | the boost (a jeep's sprint key) |
crewKitIndex | -1 | a kit the seat requires |
damageForBeingOutSideWorld | 999999 | what 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:
- Nothing when the soldier is down or dead, or when less than 1.0 second has passed since his last enter or exit.
- 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. - 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.
- 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.
| Case | Result |
|---|---|
| the same seat, or the current weapon cannot be put away (it is firing or reloading) | refused |
| the seat is free | exit and enter at once: the one-second delay does not apply |
| the seat is held by a human | refused, with a message |
| the seat is held by a bot | the 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:
- somebody sits in it: nothing;
- it is within its spawner's
distance(50 m by default): the countdown is reset; - 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;
- else the countdown runs; at zero the vehicle takes
damageWhenLostevery 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 mode | What it shows | Allowed by |
|---|---|---|
| Inside | the camera's own place, or the seat's, with shake and sway | the template (CVMInside, on by default) |
| Nose | the camera moved by nosePos | the template and the server setting sv.allowNoseCam |
| Chase | behind and above the vehicle | the template and sv.allowExternalViews |
| FrontChase | the same from the front | the same |
| FlyBy | a point ahead of the vehicle that it then passes | the same |
| Trace, ExternTrace | a following camera with a buffer | the 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:
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 pointfollowStiffness 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).
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#
| Part | State |
|---|---|
| the use handler, the entry search, the exit position and speed | verified, the same bits |
| seat switching and the swap with a bot | verified; seen in the same order as on the original server |
| abandoned vehicles | verified: 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 view | verified |
| which of several cameras a seat uses; the cockpit's sub-geometry | read as a draft; not traced to the end |
| shake, sway and bounce | not 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#
| What | Where |
|---|---|
| use, entry, exit, seat switch, abandon | crates/bf2-gameplay/src/vehicle/ (use_flow, entry, exit, seat_switch, abandon) |
| cameras | crates/bf2-gameplay/src/camera/ (chase, view) |
| the server's side | crates/bf2-server/src/vehicles_use.rs, vehicles_abandon.rs |
| seated soldiers' pose | animation |
Notes: notes/subsystems/gameplay-vehicles.md (sections 5 and 6), notes/subsystems/gameplay-cameras.md.
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.