Skip to main content

Thruster

ThrusterBehavior applies linear and angular thrust through the WASM runtime. Input lives on $thruster (thrust, rotate, optional thrustX / thrustY for vector thrust). An FSM tracks idle, active, boost, docked, and disabled modes for presentation or gating without touching Rapier directly.

Minimal example​

website/snippets/behaviors/catalog/thruster.ts:

import { ThrusterBehavior } from '@zylem/game-lib/behavior';

ship.use(ThrusterBehavior, { linearThrust: 15, angularThrust: 8 });

ship.onUpdate(({ inputs }) => {
ship.$thruster.thrust = inputs.p1.buttons.A.held > 0 ? 1 : 0;
ship.$thruster.rotate = inputs.p1.axes.Horizontal.value;
});

For twin-stick vector thrust plus shooting, use MultidirectionalSpaceShooterCoordinator instead of hand-wiring rotation and Shooter2DBehavior.

Options​

OptionDefaultNotes
linearThrust10Forward force scale.
angularThrust5Rotation torque scale.
linearDampingoptionalOverride damping.

Pitfalls​

  • Entity needs a dynamic rigid body; thrust does nothing on kinematic-only entities.
  • FSM observes input; it does not zero $thruster for you when disabled—gate input in game code if needed.

API reference​