logo
CameraFollow

camera

CameraFollow

Listens toMeshPrimitive
Free

Install with the CLI:

bjs download CameraFollow

CameraFollow

Steers a sibling ArcCamera's look-at target onto a followed entity, smoothly.

What it does

CameraFollow keeps the camera's look-at point on one entity (named by id) without snapping. The CameraFollowSystem latches that entity's mesh by listening for meshprimitive.created (and scanning entities already attached when it initializes, since MeshPrimitiveSystem can announce a handle before this System subscribes). Each frame it reads the target's world position through world.renderer.getMeshWorldPosition, runs it through a pure core that approaches the target exponentially — alpha = 1 - exp(-smoothing * dt), so doubling the frame rate produces the same arc — and writes the result with renderer.setCameraTarget. On the first frame the target is readable it snaps the core onto the target so the camera doesn't swoop in from the origin. It locates the live camera by querying for an ArcCameraComponent handle, so it never references a specific camera entity, and emits cameraFollow.targetChanged with the smoothed position every frame it moves.

Use it in a scene

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.

Fastest path

bjs download scene CameraFollow

Pulls this exact scene into your project and runs it — no copy-paste. Add --all to grab the components and assets it needs too.

Or 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 CameraFollow
    bjs download CameraFollow

    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
{
  "Camera": {
    "components": {
      "ArcCamera": { "distance": 18, "alpha": -1.5708, "beta": 0.9 }
    }
  },
  "Hero": {
    "components": {
      "MeshPrimitive": { "primitive": "capsule", "radius": 0.5, "height": 1.6, "position": [4, 0.8, 0] },
      "CameraFollow": { "target": "Hero", "smoothing": 6, "offsetY": 1.2 }
    }
  }
}

Props

  • target (string, default '') — entity id of the thing to follow; that entity must own a MeshPrimitive. Empty = the System skips this component.
  • smoothing (number, default 6) — exponential approach rate in 1/sec. 0 locks the target in place; 6 feels natural; 12 is tight.
  • offsetX (number, default 0) — added to the target's X each frame.
  • offsetY (number, default 1.2) — added to the target's Y; lifts the look-at above the mesh origin (head height rather than feet).
  • offsetZ (number, default 0) — added to the target's Z each frame.

Events

  • Emits cameraFollow.targetChanged (CameraFollowEvents.TARGET_CHANGED) every frame the target moves, with { entityId, camX, camY, camZ } — the smoothed camera target after offset.
  • Consumes meshprimitive.created ({ entityId, handle }) to latch the followed entity's MeshHandle.

Dependencies

ArcCamera — supplies the camera handle this System drives; it's found by querying for an ArcCameraComponent, so any ArcCamera entity in the scene works. MeshPrimitive — the followed entity needs one so the System has a mesh whose world position it can read.

Notes

  • The core is the source of truth for live params — the System never pushes comp.params back into it each frame, so the debug panel (CameraFollow.panel.tsx) can tune smoothing and the XYZ offset straight on the core without being clobbered.
  • ArcCamera has its own optional follow/target tracking. Pick one driver: leave ArcCamera.follow off (the default) when CameraFollow owns the look-at, or the two will both write the camera target each frame.
  • Until the target's mesh handle arrives, that component is skipped — no camera movement, no event. The first readable frame snaps the core onto the target, then smoothing takes over.

More like this

ArcCamera
MeshPrimitive
AiPilot
Animation
Asteroid
Bullet
CameraState6DOF
ChaseCamera6DOF
ChaseCameraTarget
DirectionalLight
EnemySpawner
EnvironmentTexture
FreighterCar
FreighterChain
FreighterHead
GameConfig
Health
HemisphericLight
Jump
KeyboardInput
KeyboardMover
Lifetime
LineOfSight
MachineGun
Mesh
Missile
MissileLauncher
MissionDirector
MouseInput
Movement
Obstacle
ObstacleField
OilBlob
Parts
Physics
PinballCamera
PlayerInput
PlayerWalkAnimator
RespawnTimer
RoundReset
Score
Shadow
ShipLoadout
ShooterCamera
SkeletonAnimator
SpaceShooterBullet
SpaceShooterHealth
SpaceShooterScore
TwinStickEnemy
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