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

Boats and aircraft: floats, wings, rotors and control surfaces

BF22142Heroes

A vehicle in this engine is one rigid body with children that push it. A car's children are springs and an engine. A boat's are floating bundles; an aircraft's are wings and an engine that thrusts or, for a helicopter, lifts. None of them integrates anything itself: each tick every child computes one force and adds it to the root body at its own position, and the body's step does the rest.

The car's side of this, engine and wheels: the drivetrain.

One rigid body; its children push it the root body integrates once a tick spring suspension, wheel spin engine thrust, rotor lift, wheel torque wing lift by the air across it floating bundle lift by depth in the water a force at the child's own place: off-centre, it also turns the body bf2_w32ded.exe!0x0062dc40 (spring), 0x0062ae10 (engine), 0x0062ebd0 (wing), 0x0062cb90 (floating bundle)
One body, many children. Each child's node adds a force at its own place; where the force sits decides how the body turns.

The parts#

Child objectIts physics nodeForce
SpringPhysicsSpring (bf2_w32ded.exe!0x0062dc40)the suspension; it also spins the wheel
FloatingBundlePhysicsFloatingBundle (0x0062cb90)lift by depth in the water
WingPhysicsWing (0x0062ebd0)lift by the air across its surface
Enginenone: the engine object itself (Engine::updatePhysics, 0x0062ae10)thrust, a rotor's lift, wheel torque
RotationalBundleno force: a part that turns by an input (a turret, a rudder, a flap)
LandingGearno force: a rotational bundle that folds by height and speed

The nodes update in the order they were created, each tick, after the root body's own step. A child sleeps with its root: a parked jeep computes nothing.

Floating#

A boat has several floating bundles; the boat the port was tested on has four. Each one (PhysicsFloatingBundle, template defaults hullHeight 1.0, floatMinLift 10, floatMaxLift 10):

text
d = ((y - hullHeight) - water level + offset) / hullHeight          how deep, in hull heights
nothing unless d < 0;  d below -1 becomes -1
s = clamp(pitch input - d x hullHeight, 0, 1)
lift = gravity x ((1 - s) x floatMinLift + s x floatMaxLift) x d x 0.101833
force at the float = (0, k x vertical speed there + lift, 0)

y is the float's own height, so a boat that rolls gets more lift on the low side and rights itself. The second term damps the bobbing; its factor comes from the root's drag, its mass and the area of its box, clamped to 2 either way.

Two details from the object side (FloatingBundle::update, 0x0062c9a0): the pitch input can come from an axis of the bundle; and when the boat's armor has no hit points left the input is set to -50, so a destroyed boat sinks.

On the original server a boat's four floats settle and bob with every part matrix and velocity identical to the port's for 1,004 ticks from the respawn; its water-jet engine drives, steers and coasts it identically for 320 ticks.

Wings#

A wing does not know it is on an aircraft. It has a surface, and air crosses that surface at some angle. The lift (computeLift, 0x0062ea50) is:

text
s = air speed;  u = air direction;  c = u . surface normal
a = asin(c) in degrees                         the angle of the air to the surface
k = (45 - |a|) x a / 506.25   for |a| < 45, else 0          the stall term
lift = (k x 0.75 + c x 0.25) x s^2 x scale x 0.0025
scale = gravity x (flapLift + wingLift) x -0.101833

The stall term is a curve that peaks at 22.5 degrees and is gone at 45: push the nose up too far and three quarters of the lift vanish, which is the stall every pilot of this game knows. Lift grows with the square of the speed.

The wing's node (0x0062ebd0) then applies it:

  • the air velocity is the wing point's own velocity (so a rolling aircraft's outer wing sees faster air);
  • above the water the lift is multiplied by 1 - height / ceiling, with the ceiling at 1,000 m: lift fades with height until nothing holds the aircraft up. This is the engine's flight ceiling;
  • below the water it is multiplied by 10: a wing under water is a brake;
  • the force is clamped to 200 either way and added at the wing point.

Flaps and elevators are the same object: a wing is a rotational bundle, and its pitch input turns it. The visible surface turns by the full input; the lift direction turns by only flapLift / (wingLift + flapLift) of it (Wing::update, 0x0062e450), one eleventh with the defaults. A regulated wing (liftRegulated) sets its own pitch each tick to hold a target lift: the notes' example is the F-18's landing flap, which stands at -3 degrees after a spawn.

Thrust and rotors#

The engine object makes the push (Engine::updatePhysics, 0x0062ae10). What it does depends on bits of its engine type:

EngineWhat it adds
a jet or propeller (propulsion)a force along the engine's forward axis at the engine's position, only above the water
a water jet (c_ETShip)the same, only below the water; out of the water it spins up and pushes nothing
a rotorlift along its axis from the blades' angle of attack, faded by the horizontal speed; an idle descent term; horizontal damping; a tilt near the ground
a car's or tank's enginewheel torque: see the drivetrain

A helicopter is therefore not a wing aircraft at all: its main rotor is an engine whose force points up the mast, and tilting the body tilts the force. The air density falls with height for engines too, the same ceiling as the wings'.

Sines on the hardware

The rotor's tilt uses the processor's own sine and arc tangent instructions, which do not follow the precision setting that every other operation follows. The port runs those two instructions on the hardware (a few lines of inline assembly) where the original keeps the result in a register, because a library sine differs from them in about 4 of 100 random angles at full width.

Control surfaces and turrets#

Everything that turns by an input is a RotationalBundle (0x00622fe0 its update, 0x00621490 one axis): a turret, a gun's elevation, a rudder, a steering wheel. Per axis the template gives an input, a maximum speed, an acceleration, and limits. Two modes:

  • speed: the input is a target turning speed; the speed moves toward it by the acceleration, and the angle integrates the speed (a turret);
  • automatic reset: the input is a target angle, and the part moves toward it and back to zero when the input ends (a rudder, a flap).

A mouse can move faster than a turret may turn; with rememberExcessInput the surplus is kept (up to 40) and fed in over the next ticks, so a quick flick is not lost.

The landing gear#

LandingGear (0x0062f110) extends when the aircraft is below gearDownHeight over the ground or water and slower than gearDownSpeed, and retracts above gearUpHeight and faster than gearUpSpeed; each change waits for its delay.

What the port has#

PartState
floating bundle, wing, spring nodesverified: the original's functions on original bodies, terrain and water, 200 ticks a case, the same bits
wing lift and surface angleverified
rotational bundle axis, inputverified in both precisions
the classic engine: thrust, rotor, boostverified: 10,000 ticks server and 6,000 each for three more builds and precisions
landing gearverified up to the rotational bundle's update
the regulation of an unparented bundle against the root's velocitynot reproduced, as the notes say
whole boats, jets and helicoptersrecorded drives against the original server (test rigs)

How it is tested#

  • Oracle tests: the original's vehicle components 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).
  • Statement tests (crates/bf2-physics/src/vehicle.rs, vehicle/wing.rs): the wing's constructor values from its listing, the control angle from pitch, 2142's lift arm about the turned centre of mass.
  • A winged bomb (rigid_wing.rs): its first lift and its flight against values traced from the original.
  • In play: a scenario flies each Heroes plane hands-off and asserts the heading's drift (Heroes' vehicles).

Nine of ten addresses stand in a test. The regulation of an unparented bundle is not reproduced.

In the code#

WhatWhere
the component nodescrates/bf2-physics/src/vehicle.rs
the classic engine's forcescrates/bf2-physics/src/vehicle_engine.rs
wing, floating bundle, rotational bundle, landing gear objectscrates/bf2-gameplay/src/vehicle/ (wing, floating, rotational, landing_gear)
the server's drivingcrates/bf2-world/src/vehicle_control.rs
the oraclestests/vehicle_oracle.rs, tests/engine_oracle.rs

Notes: notes/subsystems/physics-dynamics.md (sections 6a to 6c), notes/subsystems/gameplay-vehicles.md (sections 2 and 3).

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