# Chase Camera
> In a world that installs the Controllers library (`world.installLibrary({ world = "034d26cf-dc3d-4123-abad-3944f97c6a60", as = "controllers" })`), every package name on this page is written with `@controllers::` in front of it, and `asset.list("component")` lists each one under that name.
A follow cam that trails behind the target's facing at a fixed `distance` and `height`. Designed for vehicles and fast platformers where `orbital_follow`'s orbit feels too floaty.
- **The distance holds at any speed.** The camera trails the target where it is drawn this frame, and what eases is its offset from the target, so a camera set 6 m behind a car stands 6 m behind it at 5 m/s and at 200 m/s. `positionSmoothing` softens a change of the framing (the target turning, a zoom, a stick's or a finger's look, the swing back behind the target); a mouse look turns the camera on the frame the mouse moves. `rotationSmoothing` how quickly the aim swings to a new heading.
- **Collision pull-in.** Each frame a sphere of `cameraRadius` is swept from `height * 0.5` over the target itself (wherever the framed point lags) out to the camera. Sweeps of that line ahead bring the camera in ahead of what is about to come between it and the target, at the speed that has it clear when the line gets there, and something no sweep could see coming brings it in on the frame it blocks the view, so no frame is drawn from inside a wall; once the way is clear it eases back out over `pullOutTime`. With less than 0.4 m of room on the line, the camera turns round the target to the nearest turn that has it. The aim comes down from above the target toward it as the camera comes in, so a camera pulled in close still holds the target in the picture. Every collider stops the sweep, invisible ones included; `cameraIgnore` lists the ones the camera sees through.
- **Fading what fills the view.** In play a thin occluder (a post, a lamp pole, a railing: a collider no wider than `occluderFadeWidth` across the line to the target at its narrowest, and no deeper along it) does not pull the camera in: while it stands between the camera and the target it fades to `occluderFade`, that share of its pixels left undrawn in a screen-space dither. The target fades as the camera comes within `bodyFadeDistance` of the point the sweep starts from, reaching `bodyFade` at the nearest the camera stands. Each fade eases over `fadeTime`; shadows stay whole and the fade is this engine's own. `fadeIgnore` lists entities never faded, `occluderFade = 0` pulls in for every collider, and `chase:fading()` reports what fades.
- **Free-look.** The `look` control orbits the camera around the target, up to `lookYawLimit` either side and between `lookPitchMin` and `lookPitchMax`, and the camera swings back behind the target `lookReturnDelay` seconds after the control is let go. `chase:recenter()` swings it back now, over `lookReturnTime`.
- **Bumps and landings are eased.** The camera frames a point that follows the target's motion with lag: `verticalLag` (default `0.15` s) eases a bump, a ramp's lip or a landing, held to `maxVerticalLag` (`0.5` m); `horizontalLag` (default `0`, so the distance holds at any speed) and `maxHorizontalLag` do the same across the ground. `leadTime` (default `0`), `maxLead` and `leadSmoothing` run the aim ahead along the target's motion, on top of `lookAhead`. `chase:tracking()` answers the lag, the lead and the target's velocity as the rig measures them.
## Vs. `orbital_follow`
| | `orbital_follow` | `chase` |
|---|---|---|
| Orbit | look control (yaw + pitch), stays where it was left | free-look that swings back behind the target |
| Heading | the rig's own | derived from the target's facing |
| Position ease | per-axis time constants | per-second blend of the framing |
| Rotation ease | n/a | separate per-second blend |
| Best for | character action, RPG | vehicles, platformers, ski/snowboard |
## Fields
| Field | Default | Notes |
|---|---|---|
| `target` | unset | The entity to chase: the entity, its id or its name. An entity reference, so a scene build that writes it names the entity the build placed. Falls back to `Camera.follow` when unset. |
| `distance` | `6.0` | Horizontal trail distance behind target, at any speed. |
| `height` | `2.5` | Vertical offset above target origin. |
| `minDistance`, `maxDistance` | `1.5`, `25.0` | Scroll-zoom bounds. |
| `zoomSpeed` | `0.12` | `exp(-scroll * zoomSpeed)` per tick. |
| `positionSmoothing` | `0.05` | Share of a framing change left after one second. 0 = locked, 1 = static. A mouse look lands on the frame it arrives. |
| `rotationSmoothing` | `0.15` | The same for the aim swinging to a new heading. |
| `lookAhead` | `0.6` | How far in front of target the camera aims. |
| `cameraRadius` | `0.3` | Radius of the pull-in sweep. 0 turns the pull-in off. |
| `cameraIgnore` | `{}` | Entities whose colliders the pull-in passes through. |
| `pullOutTime` | `0.4` | Seconds (time constant) of the ease back out once the way is clear. |
| `occluderFade` | `0.8` | Share of a thin occluder's pixels left undrawn while it stands in the way, in play. 0 pulls in for it as for a wall. |
| `occluderFadeWidth` | `1.5` | Metres an occluder stands across the line to the target at its narrowest, and along it, at most, to fade. |
| `bodyFade` | `0.9` | Share of the target's pixels left undrawn with the camera at its nearest, in play. 0 keeps it whole. |
| `bodyFadeDistance` | `1.0` | Metres from the sweep's start within which the target fades. |
| `fadeTime` | `0.15` | Seconds a fade takes from none to full, or back. |
| `fadeIgnore` | `{}` | Entities the camera never fades. |
| `lookSensitivity` | `0.3` | Degrees per unit of the `look` control. |
| `lookYawLimit` | `180` | Degrees free-look orbits either side of behind. |
| `lookPitchMin`, `lookPitchMax` | `-60`, `15` | Degrees free-look tilts down (raising the camera) and up (lowering it). |
| `lookReturnDelay` | `1.0` | Seconds after the look is let go before the camera swings back. Negative holds it. |
| `lookReturnTime` | `0.35` | Seconds (time constant) of the swing back. |
| `invertY` | `false` | Forward on the look control looks up unless this is on. |
| `inputMap` | `cameraRigs.inputMaps.cameraRig` | The map `look` and `zoom` are read from. A write on a live rig takes up the new map. |
## Use as a camera behavior
```lua
local camera = entity.find("cam").component.get("Camera")
camera.behavior = asset.ref("cameraRigs.chase", "component")
camera.follow = car
```
The component carries the `cameraBehavior` tag in `.metadata`.
## Controls
The camera-rig map (`cameraRigs.inputMaps.cameraRig`), whose group stays live while a vehicle's map holds the player's controls:
- **Look**: right-button drag, the right stick, or a drag on the right of a touch screen. Orbits the camera; it swings back behind the target when let go.
- **Zoom**: scroll wheel, shoulder buttons, pinch. Changes `distance`.
For mouse look with no button held, point `inputMap` at a map of the world's own in the `camera` group that declares `look` and `zoom` with `pointerLock = true`: the camera group stays live while a vehicle holds the player's controls.
A vehicle that forwards its own zoom control to a chase camera (`VehicleController.camera`) leaves alone a camera that hears zoom from its own map, so one notch zooms once.
## Pair with
- `VehicleController`: the car turns, the chase camera trails its facing and holds its distance at any speed.
- `standard_controller`: the controller rotates the player to face the input direction; chase locks behind that facing.
- `cameraRigs.mount`: the same car seen from the driver's seat or the hood. Both read `Camera.follow`, so a key that switches views writes the Camera's `behavior`.
# cameraRig.inputMap
> In a world that installs the Controllers library (`world.installLibrary({ world = "034d26cf-dc3d-4123-abad-3944f97c6a60", as = "controllers" })`), every package name on this page is written with `@controllers::` in front of it, and `asset.list("component")` lists each one under that name.
The controls a camera rig reads: `move`, `look` and `zoom` for a camera the
player nudges while the cursor stays theirs: an isometric or top-down view,
a strategy camera, an orbit rig.
| Control | Keyboard + mouse | Gamepad | Touch |
|---|---|---|---|
| `move` | WASD | Left stick | Left stick |
| `look` | Mouse, while the right button is held | Right stick | Drag the right zone |
| `zoom` | Scroll wheel | Shoulders | Pinch |
The player clicks in the world these cameras show, so the cursor stays where
it is for the whole session and aiming reads a right-button drag.
`@builtin::inputMaps.default` is the scheme for a camera the player aims with
their whole view. It takes the cursor, and mouse movement steers on its own.
`look`'s right button is read as *free*: a world that binds the right button
to an action of its own gets that action from a right-drag, and this camera
keeps `look` on the pad stick and the touch zone.
The group is `camera`, which composes with whatever a world has live: a
vehicle that stands the `player` group down leaves the camera those controls
are watched through where it is.
```lua
entity.find("cam").component.add("cameraRigs.isometric", { target = "player" })
```
Every camera behaviour that reads this map takes an `inputMap` field, so a
world points one at its own map without touching the behaviour.
# cameraRigs
> In a world that installs the Controllers library (`world.installLibrary({ world = "034d26cf-dc3d-4123-abad-3944f97c6a60", as = "controllers" })`), every package name on this page is written with `@controllers::` in front of it, and `asset.list("component")` lists each one under that name.
Camera behaviors for games: a `Camera` names one in its `behavior` field and
the behavior moves and turns the camera every frame. Each carries the
`cameraBehavior` tag, so `layers.active.camera.behaviors` lists it once the
package is installed, and `orbital_follow` carries `playerDefault`, which makes
it the camera a default player is authored with.
| Behavior | What it does |
|---|---|
| `orbital_follow` | Orbits the player on three rings (low, middle, high); look turns it, the wheel zooms, and it pulls in past walls. |
| `third_person_follow` | An over-the-shoulder camera that sits behind the player and turns back behind them while they walk. |
| `first_person` | The camera at the player's eyes; seats in a `FirstPersonBody`. |
| `chase` | Trails a moving body from behind and above: a car, a boat, a runner. |
| `mount` | Rides a seat on a body: a cockpit, a hood, a turret sight. |
| `rts` | A strategy camera that pans, rotates and zooms over a map. |
| `isometric` | A fixed-angle isometric camera that pans and follows. |
| `birds_eye` | Looks straight down from overhead. |
| `orbit` | Orbits a point or an entity under the look and zoom controls. |
| `side_scroller` | Holds a 2.5D side view on a target. |
| `cinematic` | Plays a cutscene path. |
| `menu` | Holds the camera's authored pose. |
`camera_rig` is the module the follow cameras share (follow, trail, pull-in,
fades, recentring). The `cameraRig` input map binds move, look and zoom for the
`rts`, `isometric`, `birds_eye`, `orbit`, `chase` and `mount` behaviors; the
follow cameras read `@builtin::inputMaps.default`.
```luau
local cam = entity.spawn("cam")
cam.component.add("Camera", { behavior = asset.ref("cameraRigs.chase", "component") })
cam.component.get("cameraRigs.chase").target = car.id
```
`documentation/choosing-a-camera` says which behavior fits which game and the
fields each one reads. Every behavior runs looks through the player's own camera
settings (`@builtin::modules.api.engine.camera_settings`).