Understanding: Physics Engine

Learn how Fly & Fight uses Box2D for realistic physics simulation and implements custom airplane aerodynamics on top of the engine.

What is Box2D?

Industry-Standard Physics

Box2D is a free, open-source 2D physics engine created by Erin Catto in 2006. It simulates rigid body dynamics - objects with mass that can move, rotate, and collide.

Box2D has been used in many popular games:

  • Angry Birds - Physics-based puzzle game
  • Limbo - Atmospheric platformer with physics puzzles
  • Crayon Physics - Drawing-based physics game
  • Happy Wheels - Ragdoll physics game

Fly & Fight uses PhaserBox2D, a JavaScript port maintained by Phaser Studio Inc, released under MIT license.

Universal Compatibility

Same Code, Anywhere

One of Box2D's key advantages for multiplayer games is that the same physics code can run on both client and server.

Pure JavaScript

No native bindings or compiled code. Runs in any JavaScript environment.

No DOM Dependencies

Physics calculations are math-only. No canvas or browser APIs required.

Deterministic

Same inputs produce same outputs. Critical for server authority and replay.

This allows server-authoritative physics: the server runs the "real" simulation while clients run predictions for smooth gameplay.

From the Engine

Box2D Provides

FeatureWhat It Does
Rigid Body DynamicsPosition, velocity, rotation, angular velocity
Collision DetectionShapes, contact events, filtering
World SimulationGravity, time stepping, substeps
Force ApplicationForces, impulses, torques at any point

Custom Implementation

Airplane Aerodynamics

While Box2D handles the underlying physics, Fly & Fight implements custom force calculations to simulate airplane flight. These are applied every frame on top of Box2D's rigid body simulation.

Thrust

F = 7.5 N

Constant force applied along the airplane's nose direction when engine is active.

Lift

F = speed² × 0.3 × sin(AoA)

Perpendicular to velocity. Requires minimum speed of 2 m/s. Stalls beyond ±17° angle of attack. Capped at 100N.

Drag

F = speed² × 0.04

Opposes velocity direction. Simulates air resistance. Minimum speed threshold of 0.1 m/s.

Pitch Torque

τ = pitch × 0.5

Rotational force from player input. Pitch position clamped to [-2, +2] range.

Angle of Attack

Key Aerodynamics Concept

Angle of Attack (AoA) is the angle between where the airplane is pointing (nose direction) and where it's actually moving (velocity direction).

Normal Flight (AoA < 17°)

Lift increases with angle. Airplane climbs or descends smoothly based on pitch input.

Stall (AoA > 17°)

Lift drops to zero. Airplane loses control and falls. Must reduce pitch to recover.

A dead zone of 3° prevents oscillation at small angles, making flight more stable.

Try It Yourself

Interactive Demo

Physics Calculator

Coming SoonInteractive calculator will be available when physics module is published

The physics calculator will allow you to experiment with airplane aerodynamics in real-time:

Input Parameters
  • Speed (0-30 m/s)
  • Angle of Attack (-20° to +20°)
  • Thrust on/off toggle
Calculated Output
  • Lift force (N)
  • Drag force (N)
  • Stall indicator
  • Net acceleration

The calculator will use the same physics formulas as the actual game, imported from the shared physics package.

Body Configuration

Tuning Parameters

ParameterValuePurpose
Angular Damping4.0Stabilizes rotation, prevents spinning
Linear Damping0.1General air resistance
Chassis Density0.4Arcade-style lightweight feel
Wheel Friction0.9High grip for ground movement

Airplane Structure

Composite Body Design

Each airplane is a composite structure made of multiple Box2D bodies connected with joints:

Chassis

Triangle-shaped main body. Nose points in facing direction. Receives all aerodynamic forces.

Wheels

Two circular bodies (front and rear). High friction for ground movement.

Joints

Revolute joints connect wheels to chassis. Allow free wheel rotation.

Back to Fly & FightView Protocol Docs