logo

Babylon.js Market

FreighterCar

shooter · space-combat-sim

FreighterCar

1
Unlock

Install with the CLI:

bjs download FreighterCar

FreighterCar

A trailing cargo car of a freighter convoy. It follows the head snake-style, tracing the arc the locomotive drew a few seconds ago — and leaves a visible gap in the line if it's shot away.

What it does

FreighterCarComponent is pure data: its index in the chain (0 = closest to the head) and the headEntityId it follows. Each tick the FreighterChainSystem (shipped with the FreighterChain component) looks up the head, samples its recorded pose history at clock − (index+1)·carSpacingSeconds, and places the car at that historic pose — so the whole convoy slinks along the head's path. If the head has been destroyed, the car is simply left where it is with no further tracking.

The car has no System of its own; the classes and motion live in FreighterChain, pulled in as a dependency. Losing a car is incidental — the shared destroyShip path emits wingman.freighter.car.lost, which does not fail the mission (only losing the head does).

Use it in a scene

Cars name the head they follow and give their position in the line:

A scene is just data — a list of entities, each with its components. At startup the SceneLoader turns this JSON into a live world; edit the file and reload to rebuild it.

Build it from scratch with the bjs CLI:

  1. 1Scaffold a project
    npm create @babylonjsmarket/arcade@latest my-game

    World, renderer, and dev server — ready to run.

  2. 2Install dependencies
    cd my-game && npm install
  3. 3Add FreighterCar
    bjs download FreighterCar

    Copies its source into src/ so the scene resolves.

    First time? Run bjs login once.

  4. 4Paste the scene into src/scenes/arcade-room.ts and run
    npm run dev

    SceneLoader builds the world from the JSON; reload to rebuild.

JSON
{
  "FreighterCar0": {
    "tags": ["freighter-car"],
    "components": {
      "Transform6DOF": { "x": 0, "y": 0, "z": 65 },
      "FreighterCar": { "index": 0, "headEntityId": "FreighterHead" },
      "Renderable": { "shape": "freighter-car", "sx": 5, "sy": 4, "sz": 10 },
      "ShipLoadout": { "loadout": "freighter-car" }
    }
  }
}

See FreighterHead for the full head-plus-cars convoy shape.

Props

  • index (number, default 0) — position in the chain (0 = closest to the head). Sets the age offset (index+1)·carSpacingSeconds at which the car samples the head's pose history. Surviving cars keep their index on death, so gaps persist.
  • headEntityId (string, default "") — the scene key of the FreighterHead this car follows. Resolved each tick; an empty or stale id leaves the car stationary.

Dependencies

  • FreighterChain — defines FreighterCarComponent + FreighterHeadComponent and the FreighterChainSystem that samples the head's pose buffer and positions each car. A car is inert data without it.

Notes

  • Two scene keys, one system. FreighterCar and FreighterHead split the convoy into placeable entities, but both classes and all the follow logic live in FreighterChain, downloaded as a dependency of either.
  • Losing a car is cosmetic to the mission. Only the head's death (wingman.freighter.killed) fails the run; a lost car emits wingman.freighter.car.lost and just leaves a hole in the line.

More like this

FreighterChain
AiPilot
Animation
ArcCamera
Asteroid
Bullet
CameraFollow
ChaseCamera6DOF
ChaseCameraTarget
DirectionalLight
Enemy
EnemySpawner
EnvironmentTexture
FlightIntent
FreighterHead
GameConfig
Health
HemisphericLight
Jump
KeyboardInput
KeyboardMover
Lifetime
LineOfSight
MachineGun
Mesh
MeshPrimitive
Missile
MissileLauncher
MissionDirector
MoneyField
Movement
Obstacle
ObstacleField
OilBlob
Parts
Physics
PlayerFlightInput
PlayerInput
PlayerWalkAnimator
RespawnTimer
Score
Shadow
ShipFlight
ShipLoadout
ShooterCamera
SkeletonAnimator
SpaceDust
SpaceShooterBullet
SpaceShooterHealth
SpaceShooterScore
TwinStickShooter
WaveDirector
Waypoint
WaypointTrack
WorldOriginAnchor

Was this page helpful?

We read every note — tell us what's working and what isn't.

↑↓ NavigateEnter SelectEsc CloseCtrl+K Open Search