Simulate Aircraft Landing Gear with Ammo.js Raycaster
This article explains how to simulate an aircraft’s landing gear
using the btRaycastVehicle utility in the
ammo.js physics engine. While the raycaster vehicle is
primarily designed for wheeled ground vehicles like cars, its underlying
suspension, friction, and rigid body dynamics can be successfully
adapted to model realistic aircraft taxiing, takeoffs, and landings.
Why Use the Raycaster Vehicle for Aircraft?
The btRaycastVehicle in ammo.js does not
use actual cylinder-to-plane collision shapes for wheels. Instead, it
casts a ray downward from the vehicle chassis to detect the ground. When
a collision is detected, the engine calculates suspension compression,
spring forces, and damper forces.
This mechanism is highly efficient and stable, making it ideal for simulating landing gear struts. It avoids the jitter and instability often associated with complex physical constraints and joints, allowing for smooth runway operations.
Key Configuration Steps
To adapt the raycast vehicle for an aircraft, you must configure the chassis rigid body and tune the wheel parameters specifically for aviation physics.
Define the Fuselage (Chassis): Create a rigid body representing the aircraft’s fuselage. Ensure the center of mass is correctly aligned, typically forward of the main landing gear to prevent the aircraft from tipping backward (or vice versa for taildraggers).
Add the Landing Gear (Wheels): Use the
addWheel()method to define the contact points. For a standard tricycle landing gear configuration:
- Add one wheel at the nose of the aircraft.
- Add two wheels at the rear (left and right main gear).
- Tune Suspension and Forces: Aircraft require stiffer suspension and longer travel distances than cars to absorb the high impact forces of landing.
- Suspension Stiffness
(
suspensionStiffness): Set this high to handle the weight of the aircraft during hard landings. - Max Suspension Travel
(
maxSuspensionTravelCm): Increase this value to simulate long-stroke shock absorbers (struts). - Damping (
wheelsDampingCompressionandwheelsDampingRelaxation): Increase these values to prevent the aircraft from bouncing repeatedly after touching down.
Implementing Nose-Wheel Steering and Braking
The btRaycastVehicle class provides built-in methods
that make taxiing and braking straightforward: *
Steering: Apply steering angles to the nose wheel using
setSteeringValue(angle, wheelIndex). *
Braking: Apply deceleration force to the main wheels
using setBrake(force, wheelIndex). This allows for
differential braking to help steer the aircraft on the ground.
Handling Retractable Landing Gear
To simulate retractable landing gear, you cannot simply delete the wheels, as this disrupts the physics vehicle structure. Instead, you can dynamically modify the wheel properties at runtime: * Disable Collisions: Set the suspension length or travel to zero when the gear is retracted, effectively pulling the raycast point inside the fuselage where it cannot contact the ground. * Adjust Raycast Directions: Alternatively, you can toggle the activation state of the vehicle physics or temporarily ignore the vehicle’s raycast collisions when the aircraft is airborne and the gear is up.
Limitations of the Raycast Approach
While effective, the btRaycastVehicle has limitations
when used for flight simulation. The raycast is calculated along a
specific vector (usually downward relative to the vehicle). If the
aircraft performs extreme maneuvers, such as loops or steep rolls near
the ground, the raycast direction might not align correctly with the
landing surface. For highly realistic flight simulators where landing
gear can hit obstacles from any angle, a custom constraint-based physics
setup may be required. However, for standard takeoffs, landings, and
taxiing, the raycast vehicle provides an optimized and highly stable
solution.