# Birds Eye 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.
Strict overhead camera — looks straight down (-Y world) and follows the target's X/Z position. No yaw, no pitch, no orbit; only `height` (zoom).
## Vs. the other top-down behaviours
| Behavior | What it does | When to pick it |
|---|---|---|
| `birds_eye` | locked overhead, follows target XZ only | tactical / map views, navigation overlays |
| `rts` | overhead with yaw + WASD pan + RMB rotate | strategy games where the user drives the view |
| `isometric` | fixed angle (not straight down) + WASD pan | classic isometric game-feel |
## Fields
| Field | Default | Notes |
|---|---|---|
| `inputMap` | `cameraRigs.inputMaps.cameraRig` | The map whose `zoom` control adjusts the height. Point it at a world's own map to rebind this camera. |
| `target` | unset | The entity to look down on: 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. |
| `height` | `25.0` | World-Y distance above target. |
| `minHeight` | `5.0` | Scroll-zoom lower bound. |
| `maxHeight` | `120.0` | Scroll-zoom upper bound. |
| `zoomSpeed` | `0.15` | Multiplicative per scroll tick (`exp(-scroll * zoomSpeed)`). |
| `smoothing` | `0.18` | Share of an offset change left after one second. `0` snaps, `1` never moves. The target's own motion carries the camera at any speed. |
| `offsetX`, `offsetZ` | `0.0` | Constant XZ offset added to the target's position. |
## Use as a camera behavior
```lua
-- World-default
world.camera_default = asset.ref("cameraRigs.birds_eye")
-- Per-scene swap
layers.active.camera.behavior = asset.ref("cameraRigs.birds_eye")
layers.active.camera.follow = layers.active.players.localPlayer
```
The component carries the `cameraBehavior` tag in `.metadata`, so the slot validation in `Camera.behavior = ref` will accept it.
## Controls
- **Scroll** — adjust height (zoom in/out)
- No rotation, no panning — the target moves; the camera just follows.
# camera_rig
> 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.
Shared internals for the camera rigs — the parts every follow camera needs
before it gets to have a personality.
The built-in rigs (`chase`, `mount`, `cinematic`, `birds_eye`,
`third_person_follow`, `orbital_follow` and the rest) resolve their follow
target the same way, read where it is drawn the same way, ease toward their
framing measured from the subject the same way, turn a look-around the same
way, avoid geometry the same way, and write their pose the same way. Only the
placement of the camera relative to the subject differs, so everything else
lives here and the rigs stay small enough to read in one screen.
```lua
local CameraRig = require("cameraRigs.camera_rig")
local follow = CameraRig.newTrail()
function update(dt)
local target = CameraRig.resolveFollow(public.entity.id, public.follow)
if target == nil then return end
local tx, ty, tz = CameraRig.drawnPosition(target)
if tx == nil then return end
local px, py, pz = tx, ty + public.height, tz
local h, radius = CameraRig.ringAt(public.rings, public.orbitT)
local cx = px + math.sin(public.yaw) * radius
local cy = py + h
local cz = pz + math.cos(public.yaw) * radius
cx, cy, cz = CameraRig.pullIn(px, py, pz, cx, cy, cz, 0.3,
CameraRig.pullInExclude(target, public.cameraIgnore))
cx, cy, cz = CameraRig.trail(follow, tx, ty, tz, cx, cy, cz,
public.followTau, public.followTau, public.followTau, dt)
CameraRig.applyPose(public.entity.id, cx, cy, cz, px, py, pz)
end
```
## Exports
- `CameraRig.damp(current, goal, tau, dt) -> number` — exponential convergence
toward `goal`. `tau` is the time constant in seconds: the smaller it is the
tighter the camera tracks, and `0` snaps. Frame-rate independent, so a hitched
100 ms frame and six clean 16 ms frames land in the same place, and no frame
length overshoots the goal. Damp each component separately.
- `CameraRig.drawnPosition(id)`, `CameraRig.drawnForward(id)`,
`CameraRig.drawnPose(id) -> (px, py, pz, qx, qy, qz, qw)`: where a subject
is drawn this frame, which way it faces there, and its whole drawn pose. A
body the simulation moves is drawn blended between physics ticks; a rig
placed from these holds it steady on screen at any frame rate. `drawnPose`
is what a rig riding the body (a seat, a turret) places itself in the
body's frame from.
- `CameraRig.newTrail()` and `CameraRig.trail(state, subjectX, subjectY, subjectZ, goalX, goalY, goalZ, tauX, tauY, tauZ, dt) -> (x, y, z)`:
ease the camera toward its goal measured as an OFFSET from the subject.
The subject's own motion carries the camera at any speed, so a camera
framed 6 m behind stays 6 m behind at 5 m/s and at 200 m/s, and the time
constants soften only a change of the framing. Damping the camera's world
position instead leaves it `speed x tau` behind a moving subject.
- `CameraRig.carryTrail(state, frame, fromX, fromY, fromZ, toX, toY, toZ)`:
carry a change of the framing into the trail on this frame, so the camera
stands at the new framing at once; what the trail was still closing turns
about up with the framing's heading. `CameraRig.lookIsDirect(class)` says
which looks a rig carries this way: the mouse's (`"kbm"`, the device class
a look control's `onInput` names as its fourth argument), whose movement
the view follows one to one. A stick's or a finger's look eases through
the damping.
- `CameraRig.tauOf(remaining) -> number`: the time constant of a per-second
blend field (the share of a gap left after one second), for `damp` and
`trail`.
- `CameraRig.newLook()` and `CameraRig.lookAround(state, dx, dy, limits, dt) -> (yaw, pitch)`:
a look-around turned by the look control within `limits`
(`{ sensitivity, maxYaw, minPitch, maxPitch, returnDelay, returnTime, invertY? }`,
radians and seconds) that comes back to rest `returnDelay` seconds after
the input stops. Yaw is positive right, pitch positive up.
- `CameraRig.newPullIn()` and `CameraRig.pullInEased(state, pivotX, pivotY, pivotZ, camX, camY, camZ, radius, exclude, outTime, dt, frame?) -> (x, y, z)`:
`pullIn` that never cuts. Sweeps of the line ahead, from where the pivot is
moving to (no farther than its own path is clear, so a subject falling to
the ground is swept from the ground) and along where the line is turning
over the next 0.8 s, bring
the camera in ahead of what is about to come between it and its subject, at
the speed that has it clear when the line gets there; something no sweep
could see coming brings it in on the frame it blocks the view, so no frame
is drawn from behind geometry. What the sweeps ahead found stays held for
the time ahead they last found it at, so frames of uneven length (a long frame
the subject's motion comes late to, then the short one it comes in) neither
ease the camera back out nor cut it in, and motion that comes in a long frame
(a walk that starts in one) is swept ahead at once. It eases back out over `outTime`
once the way is clear. The camera stands no nearer the pivot than 0.4 m while there is
room round it: a line with less room turns the camera round the pivot about
`frame`'s up (the world's when left out) to the nearest turn that has the
room, and back onto the line once the line has it. A pivot touching a
collider is swept with a thinner sphere, and one nearer it than the thinnest
sphere has room for by a ray; a pivot inside one holds the camera as far out
as it stood. A camera standing at its framing moves with that
framing, nearer or farther, on the frame it moves. A rig whose framed point
lags its subject sweeps from the subject's own pivot, so the sweep finds
what stands between the subject and the camera.
- `CameraRig.newFade()`, `CameraRig.thinOccluders(state, aimX, aimY, aimZ, camX, camY, camZ, exclude, limits) -> { string }`,
`CameraRig.excludingThin(exclude, thin) -> { string }`,
`CameraRig.fadeOccluders(state, thin, camX, camY, camZ, aimX, aimY, aimZ, subjectId, subjectX, subjectY, subjectZ, limits, dt)`,
`CameraRig.fadeReport(state)` and `CameraRig.clearFade(state)`: a follow
camera fading what fills its view in place of its subject. `thinOccluders`
names the colliders round the framing line no wider than `limits.width`
across it at their narrowest and no deeper along it (pillars, poles,
railings); a rig hands `excludingThin(exclude, thin)` to `pullInEased` so
they do not pull the camera in, then `fadeOccluders` fades the ones on the
line from the camera to the aim point or the middle of the subject's body
to `limits.occluder`, and the subject's body by how near the camera stands
to the aim point (`limits.body` at 0.4 m, none past
`limits.bodyDistance`), each eased over `limits.time`. A fade leaves that
share of the entity's and its descendants' pixels undrawn in this engine's
camera views (`visuals.setCameraFade`); shadow views draw it whole.
`clearFade` takes every fade back at once.
- `CameraRig.pullInAim(fromX, fromY, fromZ, framedX, framedY, framedZ, heldX, heldY, heldZ, aimX, aimY, aimZ) -> (x, y, z)`:
the point a camera `pullInEased` stood looks at: the aim, brought toward
the sweep's start in step with how far the camera came in and moved with
the camera where it stands turned round the pivot, so the camera looks
along the line its framing looks along and faces its subject even when it
stands nearer the subject than the point a lagging rig frames.
- `CameraRig.newTracking()`, `CameraRig.track(state, subjectX, subjectY, subjectZ, frame, limits, dt, airborne?) -> (x, y, z)`
and `CameraRig.snapTracking(state, x, y, z)`: the point a follow rig frames,
closing on its subject over `limits.horizontalLag` (across the ground of
`frame`) and `limits.verticalLag` (along its up), held within
`limits.maxHorizontalLag` / `limits.maxVerticalLag` however fast the subject
goes. The same call measures the subject's velocity
(`CameraRig.trackingVelocity`) and eases a lead along its motion,
`limits.leadTime` seconds of it held to `limits.maxLead` and eased over
`limits.leadSmoothing` (`CameraRig.trackingLead`). A subject that moves more
than 50 m in one frame was placed there, and tracking starts over on it.
While `airborne` is true and `limits.jumpBand` is above 0, the point holds
its height as the subject rises up to `jumpBand` above it, and past the band
it rises with the subject, which stands no farther above it than the band;
a landing at another height is eased to over `verticalLag`, and a fall below
the held height is followed as on the ground. `CameraRig.airborne(subjectId)` reads whether a subject is off the
ground from its `CharacterController` or `MovementState`.
`CameraRig.trackingReport(state, recentre)` is what a rig's `tracking()`
answers.
- `CameraRig.newRecenter()`, `CameraRig.recenter(state, heading, goal, looked, weight, delay, time, dt, moving?) -> heading`
and `CameraRig.requestRecenter(state)`: a heading that turns back toward
`goal` the short way round once look input has stopped for `delay` seconds
(at once after a request; a negative `delay` turns only on request), over a
time constant of `time`, its rate scaled by `weight`; a frame whose
weight is 0 holds the heading and starts the wait over. Told whether the
subject moves (`moving`, from `CameraRig.subjectMoving(frame, vx, vy, vz)`:
faster than 0.5 m/s across the ground), a look the player made holds the
heading for as long as the subject stands, and the wait starts once it
moves off; a request ends that hold.
`CameraRig.recenterGoal(frame, subjectId, to, tracking)` is the heading
behind the subject's facing (`"facing"`) or its motion (`"motion"`), and
`CameraRig.recenterWeight(frame, heading, goal, vx, vy, vz)` the share of
the rate that keeps a camera from turning a subject it steers round in
circles: the square of the share of the facing that points away from the
camera while the subject moves, 1 at rest. `CameraRig.headingOf(frame, x, y, z)` is the
heading a rig looking along a direction holds.
- `CameraRig.facingSource(subjectId) -> string?`: what `visibleForward` reads
the subject's facing from (its `Locomotion` or `LocomotionFull`, the anchor
that turns and the direction the component declares along it), as one key,
nil while the subject's own transform is its facing. The key changes when
the facing becomes known (the component arrives, a body stands up under
the character) or is declared anew (`Locomotion.forward` or
`LocomotionFull.faceSign` changes), and holds while the body turns. A
follow rig aims behind its subject when it binds it and again when this
key changes, so a character whose facing arrives after the camera bound
(an avatar that composes late) is framed from behind.
- `CameraRig.ringAt(rings, t) -> (number, number)` — height and radius of the
orbit at `t` along the path through the three rings, where `rings` is
`{ bottom = { height, radius }, center = ..., top = ... }`. `t` runs 0 at the
bottom ring to 1 at the top, passing exactly through the centre ring at 0.5.
The path is a curve through the three rings that turns no corner at the
centre ring: it heads there halfway between the directions of its two
stretches. Out-of-range `t` clamps rather than extrapolating.
- `CameraRig.ringLook(rings, aimHeight, radiusScale, t, angle) -> number`: where
along the path a vertical look of `angle` radians puts the camera. Positive
moves toward the top ring. Where the path runs within about 78 degrees of
round the aim point, the view pitches by the look's angle, so a rig turns at
one rate up and down and sideways. Where it heads more steeply toward or
away from the aim point, the look moves the camera along it by five times
the angle times the camera's distance from the aim point, the farthest a
look moves it anywhere on the rings: a stretch with little or no pitch to
turn takes a look the way any other stretch does, and rings authored a
fraction of a degree apart move the camera alike. The look carries through a ring into
the next stretch, a stretch between two rings that stand in one place
takes none of it, and the result stays in 0..1.
- `CameraRig.resolveFollow(selfId, followField) -> string?` — the entity this
rig follows. Takes the rig's own `follow` field (an entity id or an entity
reference) when it is set, and otherwise falls back to the `Camera.follow`
slot, which is the standard place every camera behavior reads its target
from — that is what makes "swap the behavior, keep the follow target" work.
Returns `nil` when nothing is set AND when the resolved id has no live
entity, which is the normal state for the first frames of play mode while
the avatar is still spawning.
- `CameraRig.pullIn(pivotX, pivotY, pivotZ, camX, camY, camZ, radius, exclude?) -> (number, number, number)`:
the camera position moved in along the pivot-to-camera line until no
collider is between the two. A sphere of `radius` is swept from the pivot,
and every collider in the world stops it, whether or not anything draws it:
an invisible walk bound and a trigger volume pull the camera in exactly as a
wall does. `radius` is also the distance kept off the surface the camera
lands on; `0` turns the pull-in off and returns the input untouched.
`exclude` is an entity id, or a list of them, whose colliders the sweep
passes through: the subject the camera is looking at, plus anything the
camera should see through. A pivot standing against a collider, so the
sphere starts touching it, is swept again with half the radius and then a
quarter, which slides along it, and a pivot nearer it than that is answered
by a ray; a pivot inside a collider has no line out, and the camera position
comes back untouched.
- `CameraRig.pullInExclude(subjectId, ignore) -> { string }`: the exclude
list a rig hands `pullIn`: the subject first, then every entity in the rig's
`cameraIgnore` list (ids or entity proxies). `orbital_follow` and
`third_person_follow` both build theirs with it from their `cameraIgnore`
field. A rig written on this module gives its authors the same control by
declaring a `cameraIgnore` list of its own
(`Field.list(Field.entityRef(nil, Sync), Sync)`) and passing it here.
- `CameraRig.applyPose(selfId, camX, camY, camZ, lookX, lookY, lookZ)` — place
the camera and aim it at a point. Both the pose and the aim point are in the
camera entity's own transform frame: parent-relative when the camera is
parented to its subject, world space when it is standalone. The write goes
to the local transform, so transform propagation composes the world matrix
from `parent_world * local` instead of being fought by a world-space write.
# 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`.
# Cinematic 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.
Wide-FOV, slow-easing follow with a configurable over-the-shoulder offset. Intended for cutscenes, dialogues, and walking moments where you want a more composed framing than `orbital_follow` and softer motion than `chase`.
The camera holds a right-shoulder offset relative to the target's facing and eases both position and look-at point as offsets from the target, so quick turns feel cinematic rather than jittery while the target stays framed at any speed: the smoothing softens a change of the framing, and the target's own motion carries the camera with it.
## Vs. the other follow cams
| | `orbital_follow` | `chase` | `cinematic` |
|---|---|---|---|
| Orbit (mouse) | yes | no | no |
| Framing ease | n/a | low (sticky) | high (cinematic) |
| Look-at ease | n/a | low | even higher than position |
| Composition | centered behind | locked behind | shoulder-framed |
| Best for | character action | vehicles, fast | cutscenes, walking, dialogue |
## Fields
| Field | Default | Notes |
|---|---|---|
| `target` | unset | The entity to film: 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` | `4.5` | Trail distance behind target. |
| `height` | `1.8` | Vertical offset above target origin. |
| `shoulderX` | `0.6` | Right-shoulder offset (negative = left shoulder). |
| `fov` | `60.0` | Pushed once to the sibling `Camera` component on `awake`. |
| `positionSmoothing` | `0.35` | Share of a framing change left after one second. High = slow, cinematic. |
| `lookAtSmoothing` | `0.45` | Higher than position so framing reads as "anticipating". |
## Use as a camera behavior
```lua
world.camera_default = asset.ref("cameraRigs.cinematic")
-- Or per-scene
layers.active.camera.behavior = asset.ref("cameraRigs.cinematic")
layers.active.camera.follow = layers.active.players.localPlayer
```
The component carries the `cameraBehavior` tag in `.metadata`.
## Notes
- No user-driven rotation, no scroll-zoom — `cinematic` is set-it-and-let-it-frame.
- Swap `shoulderX` for a left-shoulder shot. Sign-flip in script for an interactive switch.
- Pairs especially well with `humanoid_visual` + `standard_controller` for narrative gameplay.
# controller.first_person
> 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.
First-person camera controller. Positions the camera at an entity's location (+ eye-height offset) and rotates with mouse look.
It resolves its follow target in this order: its own `target` field, then `Camera.follow` when `target` is unset, then the static `posX/posY/posZ` when neither is set. `Camera.follow` is the standard slot every behavior reads, so a first-person camera selected through `Camera.behavior` tracks whatever `Camera.follow` points at, the correct source for a player camera, whose body id is minted fresh per spawned clone and cannot be authored onto the behavior ahead of time.
Public fields: `target` (the entity to follow: the entity, its id or its name, kept as an entity reference; unset uses `Camera.follow`, then `posX/Y/Z`), `posX`, `posY`, `posZ`, `offsetX`, `offsetY` (eye height above target origin), `offsetZ`, `sensitivity`, `minPitch`, `maxPitch`.
Controls: pointer lock to rotate (yaw + pitch), which the standard scheme
takes while the world runs. With the cursor handed back, an RMB drag rotates
too — for as long as nothing else in the world binds the right button.
```luau
-- Track the Camera's follow target (set Camera.follow, no id authored here):
entity(id).component.add("cameraRigs.first_person", { offsetY = 1.6 })
-- Or a static camera at a fixed position:
entity(id).component.add("cameraRigs.first_person", { posX = 0, posY = 1.6, posZ = 3 })
```
# 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.
# controller.isometric
> 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.
Isometric camera controller. Fixed-angle overhead camera (classic isometric view). WASD to pan on the XZ plane, scroll to zoom. The viewing angle is fixed (no rotation).
Public fields: `inputMap` (the camera-rig scheme, `cameraRigs.inputMaps.cameraRig`, by default; point it at a world's own map to rebind this camera), `target` (the entity to follow: the entity, its id or its name, kept as an entity reference; unset follows `Camera.follow`, else pans free), `centerX`, `centerY`, `centerZ`, `distance`, `minDistance`, `maxDistance`, `moveSpeed`, `zoomSpeed`, `yaw` (default pi/4), `pitch` (default ~35.26 degrees).
Controls: WASD to pan (world-axis-aligned), scroll to zoom.
```luau
entity(id).component.add("cameraRigs.isometric", { distance = 12, moveSpeed = 8 })
```
# menu
A camera behavior that holds the camera's authored pose: name it in a `Camera`'s `behavior` for a title screen or a menu backdrop, and the camera stays where it was placed.
# controller.mount
> 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 camera that rides a body: it stands at a point of the body's own frame,
faces an orientation in that frame, and moves with the body where it is drawn
each frame, so it stays on its seat as the body drives, turns, pitches and
rolls, smooth whatever the physics tick rate and the frame rate. A driver's
seat, a hood or bumper view, a helmet, a turret sight, a boat's bridge, a
coaster car, a mech's cockpit.
```luau
local cam = entity.spawn("cockpit")
local camera = cam.component.add("Camera", { fov = 70 })
camera.behavior = asset.ref("cameraRigs.mount", "component")
camera.follow = car
local mount = cam.component.get("cameraRigs.mount")
mount.offset = { x = -0.35, y = 0.9, z = 0.2 } -- the driver's eye, in the car's frame
mount.headMotion = 0.04 -- the head moves with braking and cornering
```
A key that switches between this view and a chase view behind the car writes
the Camera's `behavior` (`cameraRigs.chase` reads the same
`Camera.follow`):
```luau
camera.behavior = asset.ref("cameraRigs.chase", "component") -- behind the car
camera.behavior = asset.ref("cameraRigs.mount", "component") -- back in the seat
```
A hood view is the same rig with `offset` on the bonnet; a rear view turns it
round with `mountYaw = 180`; a turret sight puts `follow` on the turret's own
entity, which the rig reads the drawn pose of like any body.
## Fields
| Field | Default | Notes |
|---|---|---|
| `follow` | empty | The body to ride. Empty takes the Camera's `follow` slot. Any entity: a body, or an entity parented under one (a seat, a turret), read where it is drawn. |
| `offset` | `{0, 1.2, 0}` | Where the camera stands: metres along the body's own axes, x right, y up, z back (a car's forward is its local -Z). |
| `mountYaw` | `0` | Degrees the view is turned right of the body's forward. |
| `mountPitch` | `0` | Degrees the view is tilted up from the body's forward. |
| `lookSensitivity` | `0.3` | Degrees per unit of the `look` control. |
| `lookYawLimit` | `120` | Degrees the look turns either side of the mount's direction. |
| `lookPitchMin`, `lookPitchMax` | `-45`, `45` | Degrees the look tilts down and up. |
| `lookReturnDelay` | `0.6` | Seconds after the look is let go before the view comes back. Negative holds the look. |
| `lookReturnTime` | `0.25` | Seconds (time constant) of the view coming back. |
| `invertY` | `false` | Forward on the look control looks up unless this is on. |
| `headMotion` | `0` | Metres the eye moves against each g of acceleration along the body's forward and side axes; the view leans with it, dipping under braking and swaying out of a turn. 0.04 is a belted driver. |
| `headLag` | `0.12` | Seconds (time constant) the head takes to follow a change of acceleration. |
| `inputMap` | `cameraRigs.inputMaps.cameraRig` | The map `look` is read from. The camera-rig map stays live while a vehicle holds the player's controls. A write on a live rig takes up the new map. |
## How it moves
The rig reads `Physics.drawnPose` of its body every frame: the pose the frame
draws the body at, blended between physics ticks. A camera placed from the
body's transform (`entity.position`) would move in whole ticks while the body
is drawn between them, and the cabin would shake on screen.
Head motion reads a motion probe the rig places at the mount point
(`Physics.probeMotion`) on the rigid body that carries `follow`: the followed
entity's own body, or for a seat or a turret entity the body it is parented
under. The probe reads the acceleration a rider there feels, which the rig
turns into the followed entity's own axes. A body this peer does not simulate
gives the probe nothing to read, and the head holds still on it.
The camera entity stands unparented: the rig writes its world pose every
frame.
## Controls
- **Look**: right-button drag, the right stick, or a drag on the right of a
touch screen (the camera-rig map). The view returns to the mount's
direction once the control is let go.
For mouse look with no button held, point `inputMap` at a map of the world's
own in the `camera` group that declares `look` with `pointerLock = true`: the
camera group stays live while a vehicle holds the player's controls.
# controller.orbit
> 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.
Orbit camera controller. Orbits around a target entity or position. Mouse drag to rotate, scroll to zoom, optional auto-rotate.
Public fields: `inputMap` (the camera-rig scheme, `cameraRigs.inputMaps.cameraRig`, by default; point it at a world's own map to rebind this camera), `target` (the entity to orbit: the entity, its id or its name, kept as an entity reference; unset orbits `Camera.follow`, else `targetX/Y/Z`), `targetX`, `targetY`, `targetZ`, `distance`, `minDistance`, `maxDistance`, `sensitivity`, `zoomSpeed`, `autoRotate`, `autoRotateSpeed`.
Controls: RMB drag to rotate, scroll to zoom.
```luau
entity(id).component.add("cameraRigs.orbit", { target = "player", distance = 10 })
```
# orbital_follow
> 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.
Three-ring orbit camera. Framing is authored as three rings around the follow target: a bottom, a centre and a top, each with a `height` above the target's origin and a `radius` out from its axis. Vertical look slides the camera along a smooth path through those rings, as far as it takes to turn the view by the look's angle; horizontal look orbits around them. The shape of the orbit is geometry you can see and edit rather than a pair of pitch limits you cannot.
Public fields: `follow`, `ringBottom` / `ringCenter` / `ringTop` (each `{ height, radius }`), `verticalAxis` (0 at the bottom ring, 1 at the top), `horizontalAxis` (the world heading the camera looks along, in radians about +Y from world +Z), `radiusScale`, `aimHeight` (the aim point above the target's origin), `damping` (per-axis time constants in seconds of the camera's offset from the point it frames: they soften a change of framing, a stick or touch look, a zoom or a recentre; a mouse look turns the camera on the frame the mouse moves), `horizontalLag`, `verticalLag`, `maxHorizontalLag`, `maxVerticalLag`, `jumpBand`, `leadTime`, `maxLead`, `leadSmoothing`, `recenterDelay`, `recenterTime`, `recenterTo`, `pullOutTime` (see below), `cameraRadius` (radius of the pull-in sweep; `0` turns the pull-in off), `cameraIgnore` (entities whose colliders the pull-in passes through), `occluderFade`, `occluderFadeWidth`, `bodyFade`, `bodyFadeDistance`, `fadeTime`, `fadeIgnore` (fading thin occluders and the subject's body, see below), `sensitivity` (radians the view turns per unit of look, the same in heading and in pitch wherever the rings run within about 78 degrees of round the aim point, as the default rings do at every `radiusScale` from 0.2 to 3; where they head more steeply toward or away from it, a vertical look moves the camera along them by five times that angle times its distance from the aim point), `invertY` (off by default: pushing the mouse forward looks UP, drawing the camera toward the bottom ring; on pitches the other way), `zoomSpeed`, `minRadiusScale`, `maxRadiusScale`.
The rig owns that heading. Binding a follow target aims it along the subject's facing, so the shot opens from behind whoever the camera is told to follow, and look input turns it from there and the recentre turns it back behind the subject once the player stops looking around (below). A facing that becomes known or is declared anew after the bind aims it behind the subject again, once for each change: a `Locomotion` or `LocomotionFull` arriving on the subject or leaving it, a body standing up under it, as an avatar that composes after the camera bound does, or the component's `forward` or `faceSign` changing (`CameraRig.facingSource` names what the facing is read from). The heading holds while the body turns. That is what makes the camera steerable for a character who turns to face where it is walking: hold "forward" and the character walks the line the camera looks down, instead of chasing a heading that moves as it turns.
The default rings frame a roughly 1.8 m humanoid standing at its origin: the centre ring sits above head height at the widest radius for a resting shot from behind and slightly above, the bottom ring drops to knee height and pulls in to look up, and the top ring climbs and tightens for a near-overhead look down.
In edit mode, or while play is paused, writing any framing field re-poses the rig immediately with damping bypassed, so editing a ring moves the camera to the shot that ring describes. While play runs, a write steers the rig: its next tick takes the new framing through the damping and the pull-in, the way it takes look input, so a script that turns the camera by writing `horizontalAxis` swings it round over frames, coming in ahead of a wall as a look does.
`follow` falls back to the `Camera.follow` slot when it is empty, so a rig selected through `Camera.behavior` tracks whatever that camera already follows.
Controls: mouse to orbit and to slide along the rings (play mode requests pointer lock, so no button is held), scroll to scale the ring radii.
```luau
local cam = entity(id).component.get("Camera")
cam.behavior = asset.ref("cameraRigs.orbital_follow", "component")
entity(id).component.get("cameraRigs.orbital_follow").ringCenter = { height = 2.6, radius = 6 }
```
## Following the subject: lag, lead and recentre
The camera frames a point that follows its subject's motion with lag, so a step, a stair, a landing, a start, a stop or a reversal is eased rather than copied:
- `horizontalLag` / `verticalLag` (defaults `0.2` / `0.25` s) are the time constants of that point closing on the subject across the ground and along up; `0` carries that motion on the frame it happens.
- `maxHorizontalLag` / `maxVerticalLag` (defaults `1.0` / `0.75` m) bound how far the subject gets from that point, however fast it goes, so the subject never leaves the middle of the frame by more.
- `jumpBand` (default `1.5` m) holds the camera's height through a jump: while the subject is off the ground (its `CharacterController`, or `MovementState`, reads it so) it rises up to this far above the framed height with the camera standing still, so a jump that lands where it took off moves the view along up not at all. Past the band the camera rises with the subject, which stands no farther above the framed height than the band, so a higher jump or a launch keeps it in the picture. A landing higher or lower is eased to over `verticalLag`, and a fall below the framed height is followed as on the ground. `0` follows every jump.
- `leadTime` (default `0.3` s), `maxLead` (`1.5` m) and `leadSmoothing` (`0.5` s): the aim runs ahead of the subject along its motion across the ground by its speed times `leadTime`, held to `maxLead` and eased as the subject starts, stops and turns, so the player sees where the subject is going. `0` aims at the subject.
- `recenterDelay` (default `2` s) and `recenterTime` (`1.25` s): in play, once look input has stopped for `recenterDelay` the heading turns back behind the subject over a time constant of `recenterTime`. `recenterTo` names what it turns behind: `facing` (the default), the way the subject visibly faces (its -Z, or the facing its `Locomotion` or `LocomotionFull` turns, `CameraRig.visibleForward`), or `motion`, the way it moves across the ground. While the subject moves the turn runs at the square of the share of its facing that points away from the camera (half the rate at 45 degrees off the view), so a subject running across the view or toward the camera keeps the heading where it is, rather than the camera and the subject turning each other round, and once it stops the turn waits `recenterDelay` again. A look the player makes while the subject stands holds the heading for as long as it stands: the wait starts once the subject moves off, and a subject that stops again with no look since turns behind after `recenterDelay`. A negative `recenterDelay` turns only on `rig:recenter()`, which turns the heading back now from any delay and ends a look's hold.
- `pullOutTime` (default `0.4` s): once the way is clear the camera eases back out over this time constant. The pull-in itself never cuts (below).
Setting the two lags and `leadTime` to `0` gives the camera that carries its subject's motion on the frame it happens. `rig:tracking()` answers how the camera follows right now: `lag` (how far the subject stands from the framed point), `lead`, `velocity` (the subject's, as the rig measures it), `recentering`, `idle` (seconds since look input) and `lookHeld` (a look the player made holds the heading while the subject stands).
```luau
local rig = entity(camId).component.get("cameraRigs.orbital_follow")
rig.verticalLag = 0.4 -- ease stairs and jumps more
rig.recenterDelay = -1 -- keep the heading the player leaves it at
rig:recenter() -- and turn it behind the subject on a button
```
## The camera pulls in when a collider is in the way
Each frame the rig sweeps a sphere of `cameraRadius` from the aim point over the subject itself (`aimHeight` above it, wherever the framed point lags) out to where its framing puts the camera, and stands the camera where the sphere first meets a collider. Every collider in the world stops that sweep, whether or not anything draws it: an invisible walk bound (a `BoxCollider` with no `Model`), a trigger volume and a solid wall all pull the camera in alike. The follow subject is the one entity the sweep passes by default.
The pull-in never cuts. Sweeps of that line ahead, from where the subject is moving to and along where the line is turning over the next 0.8 s, bring the camera in ahead of a wall end or a pillar about to come between it and the subject, at the speed that has it clear when the line gets there; only something no sweep could see coming (a wall that appears) brings it in on the frame it blocks the view, so no frame is drawn from behind geometry. The camera stands no nearer the sweep's start than 0.4 m while there is room round it: when the line has less room than that (the subject against a wall or a pillar the camera is behind), the camera turns round the subject about its up to the nearest turn that has the room, keeps looking the way its framing looks, and turns back onto the line once the line has the room again. A start touching a collider is swept with a thinner sphere, which slides along it, a start nearer it than the thinnest sphere has room for by a ray, and a start inside one holds the camera as far out as it stood.
So a camera that snaps in close to the player, or collapses onto it, while nothing visible stands behind the player is meeting a collider nobody can see. Two fields settle it:
- `cameraIgnore` lists the entities whose colliders the camera sees through. Name the walk bounds and gameplay volumes there and the sweep passes them as it passes the subject, while walls the player can see still pull the camera in. Each entry is an entity (or its id), and it is the collider's own entity that is listed.
- `cameraRadius = 0` turns the pull-in off: the camera stands where its framing puts it, through every collider.
```luau
local rig = entity(camId).component.get("cameraRigs.orbital_follow")
rig.cameraIgnore = { entity.find("NorthBound"), entity.find("SouthBound") }
-- or drop the pull-in entirely
rig.cameraRadius = 0
```
## Thin occluders and the subject's body fade instead of filling the view
In play the camera fades what would otherwise fill the view in place of the subject. A thin occluder (a pillar, a pole, a post, a railing, a doorframe's jamb, a tree trunk: a collider no wider than `occluderFadeWidth` across the line from the camera to the subject at its narrowest, and no deeper along it) does not pull the camera in: the sweeps pass it, and while it stands between the camera and the subject it fades to `occluderFade`, that share of its pixels left undrawn in a screen-space dither so the subject shows through. Walls, floors and every collider wider or deeper than that still pull the camera in, as above. The subject's own body fades as the camera comes within `bodyFadeDistance` of the aim point, reaching `bodyFade` at the nearest the camera stands (0.4 m), so a camera pulled in against a wall shows what lies past the subject rather than the back of its head. Each fade eases in and out over `fadeTime`, never in one frame.
A fade covers the entity and its descendants, in this engine's own views (each player's camera sets its own), and shadows stay whole. `fadeIgnore` lists entities the camera never fades: they pull it in whatever their size. `occluderFade = 0` brings back the pull-in for every collider, and `bodyFade = 0` keeps the body drawn whole. `rig:fading()` reports what the camera fades this frame, and `renderer.drawStats().cameraFaded` how many renderables carry a fade.
```luau
local rig = entity(camId).component.get("cameraRigs.orbital_follow")
rig.fadeIgnore = { entity.find("GateLever") } -- a lever the player must always see
rig.occluderFade = 0 -- or pull in for every collider
```
## Attach through `Camera.behavior`
The Camera owns the behavior slot, so assigning the rig there is what lets the Camera tell it when `follow` changes. A rig added straight onto the entity with `component.add` still poses, but the Camera does not know about it and a `follow` assigned afterwards will not reach it.
## Player cameras: leave `follow` unset
Entering play drops and respawns `PlayerPrototype` subtrees, so the body is recreated with a NEW entity id. A `follow` authored on the rig keeps pointing at the original, which is no longer live, and the camera freezes at its last pose instead of tracking the player.
For a player camera, set the target on the **Camera** and leave the rig's own `follow` empty:
```luau
entity(rigId).component.get("Camera").follow = body -- PlayerPrototype rebinds this on every spawn
```
`PlayerPrototype` refreshes `Camera.follow` to the live body each time it clones, and the rig reads that slot whenever its own `follow` is empty. Set the rig's `follow` only for a camera that watches a fixed, non-respawning subject.
# controller.rts
> 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.
RTS camera controller. Top-down strategy camera. WASD to pan (aligned to camera yaw), scroll to zoom, right-click drag to rotate. Optionally lock to a target entity.
Public fields: `inputMap` (the camera-rig scheme, `cameraRigs.inputMaps.cameraRig`, by default; point it at a world's own map to rebind this camera), `target` (the entity to follow: the entity, its id or its name, kept as an entity reference; unset follows `Camera.follow`, else pans free with WASD), `centerX`, `centerY`, `centerZ`, `distance`, `minDistance`, `maxDistance`, `moveSpeed`, `sensitivity`, `zoomSpeed`, `minPitch`, `maxPitch`.
Controls: WASD to pan, scroll to zoom, RMB drag to rotate.
```luau
entity(id).component.add("cameraRigs.rts", { distance = 15, moveSpeed = 12 })
```
# controller.side_scroller
> 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.
Side-scroller camera controller. Fixed-offset camera that follows a target from the side (classic 2.5D perspective). Maintains a constant position relative to the target and looks slightly ahead.
Public fields: `target`, `centerX`, `centerY`, `centerZ` (fallback), `offsetX`, `offsetY`, `offsetZ` (camera offset from target), `lookAheadX`, `lookAheadY`, `lookAheadZ` (look-at offset from target).
Controls: none — follows the target automatically.
```luau
entity(id).component.add("cameraRigs.side_scroller", { target = "player", offsetX = -8, offsetY = 3 })
```
# controllers_camera_input
Tests for the camera rigs and their input maps: a repointed `inputMap` field, a rig disabled, attached disabled or under an inactive parent standing its map down, the registrations a rig gives up with itself across a pause, and the control scheme a gameplay camera behaviour brings.
Run it in an engine bound to the Controllers world, or a world that installs it:
`asset.resolve("controllers_camera_input", "testSuite"):run()`.
# controllers_camera_play
Tests for the camera rigs in play: a first-person camera keeping the pose it was authored with, orbital_follow framing writes, a character walking where a look turns the rig, a rig treating what its subject carries as its own, the first-person and chase rigs reading `Camera.follow`, and inputSim aiming through a third-person rig.
Run it in an engine bound to the Controllers world, or a world that installs it:
`asset.resolve("controllers_camera_play", "testSuite"):run()`.
# controllers_camera_rigs
Tests for the camera_rig module and the follow rigs built on it: the damping and three-ring spline as functions over numbers, the pull-in sweep against real colliders and each follow rig's `cameraIgnore`, the follow rigs holding their framing from a fast body, lagging, leading and recentring on it, fading what fills the view, the chase rig's pull-in and free-look, the mount rig riding a body, the rigs answering the hand and a finger, and the player's camera settings.
Run it in an engine bound to the Controllers world, or a world that installs it:
`asset.resolve("controllers_camera_rigs", "testSuite"):run()`.
# controllers_cameras
Tests for the cameraRigs package of the Controllers world: every behavior
carries the `cameraBehavior` tag, the overhead and vehicle cameras read the
package's cameraRig input map, a chase camera trails its target, and
orbital_follow is the camera a default player is authored with. Run it in an
engine bound to the Controllers world, or a world that installs it:
`asset.resolve("controllers_cameras", "testSuite"):run()`.
# third_person_follow
> 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.
Over-the-shoulder camera. The rig hangs off a shoulder pivot beside the follow target and sits back along the heading it looks down, so framing is authored as offsets in space. The offset is measured in the camera's own frame, so the subject holds the same spot on screen whichever way it turns.
The rig owns that heading. Binding a follow target aims it along the subject's facing, and look input turns it from there and the recentre turns it back behind the subject once the player stops looking around (below). A facing that becomes known or is declared anew after the bind aims it behind the subject again, once for each change: a `Locomotion` or `LocomotionFull` arriving on the subject or leaving it, a body standing up under it, as an avatar that composes after the camera bound does, or the component's `forward` or `faceSign` changing (`CameraRig.facingSource` names what the facing is read from). The heading holds while the body turns. That is what makes the camera steerable for a character who turns to face where it is walking: hold "forward" and the character walks the line the camera looks down, instead of chasing a heading that moves as it turns.
The facing a bind reads is the way the body visibly faces (`CameraRig.visibleForward`): a composed avatar body faces its -Z, turned by `Locomotion` or `LocomotionFull` as it walks, read through the rotation anchor that component turns, so the rig lands behind every avatar whatever file its body came from and after `setCharacter` swaps its body. A target with neither component answers its transform forward.
Public fields: `follow`, `shoulderOffset` (x across the frame, y up it, z along the heading), `verticalArmLength`, `cameraSide` (0 = left shoulder, 1 = right), `cameraDistance`, `minDistance`, `maxDistance`, `aimYaw` (the world heading the camera looks along, in radians about +Y from world +Z) and `aimPitch` (how far it tilts off level), `damping` (per-axis time constants in seconds of the camera's offset from the point it frames: they soften a change of framing, a stick or touch look, a zoom or a recentre; a mouse look turns the camera on the frame the mouse moves), `horizontalLag`, `verticalLag`, `maxHorizontalLag`, `maxVerticalLag`, `jumpBand`, `leadTime`, `maxLead`, `leadSmoothing`, `recenterDelay`, `recenterTime`, `recenterTo`, `pullOutTime` (see below), `cameraRadius` (radius of the pull-in sweep; `0` turns the pull-in off), `cameraIgnore` (entities whose colliders the pull-in passes through), `occluderFade`, `occluderFadeWidth`, `bodyFade`, `bodyFadeDistance`, `fadeTime`, `fadeIgnore` (fading thin occluders and the subject's body, see below), `sensitivity`, `invertY` (off by default: pushing the mouse forward looks UP; on pitches the other way), `zoomSpeed`, `minPitch`, `maxPitch`.
In edit mode, or while play is paused, writing any framing field re-poses the rig immediately with damping bypassed, so edit mode shows the framing play mode will produce. While play runs, a write steers the rig: its next tick takes the new framing through the damping and the pull-in, the way it takes look input, so a script that turns the camera by writing `aimYaw` swings it round over frames, coming in ahead of a wall as a look does.
`follow` falls back to the `Camera.follow` slot when it is empty, so a rig selected through `Camera.behavior` tracks whatever that camera already follows.
Controls: mouse to look (play mode requests pointer lock, so no button is held), scroll to adjust `cameraDistance`.
## Following the subject: lag, lead and recentre
The camera frames a point that follows its subject's motion with lag, so a step, a stair, a landing, a start, a stop or a reversal is eased rather than copied:
- `horizontalLag` / `verticalLag` (defaults `0.2` / `0.25` s) are the time constants of that point closing on the subject across the ground and along up; `0` carries that motion on the frame it happens.
- `maxHorizontalLag` / `maxVerticalLag` (defaults `1.0` / `0.75` m) bound how far the subject gets from that point, however fast it goes, so the subject never leaves the middle of the frame by more.
- `jumpBand` (default `1.5` m) holds the camera's height through a jump: while the subject is off the ground (its `CharacterController`, or `MovementState`, reads it so) it rises up to this far above the framed height with the camera standing still, so a jump that lands where it took off moves the view along up not at all. Past the band the camera rises with the subject, which stands no farther above the framed height than the band, so a higher jump or a launch keeps it in the picture. A landing higher or lower is eased to over `verticalLag`, and a fall below the framed height is followed as on the ground. `0` follows every jump.
- `leadTime` (default `0.3` s), `maxLead` (`1.5` m) and `leadSmoothing` (`0.5` s): the aim runs ahead of the subject along its motion across the ground by its speed times `leadTime`, held to `maxLead` and eased as the subject starts, stops and turns, so the player sees where the subject is going. `0` aims at the subject.
- `recenterDelay` (default `2` s) and `recenterTime` (`1.25` s): in play, once look input has stopped for `recenterDelay` the heading turns back behind the subject over a time constant of `recenterTime`. `recenterTo` names what it turns behind: `facing` (the default), the way the subject visibly faces (its -Z, or the facing its `Locomotion` or `LocomotionFull` turns, `CameraRig.visibleForward`), or `motion`, the way it moves across the ground. While the subject moves the turn runs at the square of the share of its facing that points away from the camera (half the rate at 45 degrees off the view), so a subject running across the view or toward the camera keeps the heading where it is, rather than the camera and the subject turning each other round, and once it stops the turn waits `recenterDelay` again. A look the player makes while the subject stands holds the heading for as long as it stands: the wait starts once the subject moves off, and a subject that stops again with no look since turns behind after `recenterDelay`. A negative `recenterDelay` turns only on `rig:recenter()`, which turns the heading back now from any delay and ends a look's hold.
- `pullOutTime` (default `0.4` s): once the way is clear the camera eases back out over this time constant. The pull-in itself never cuts (below).
Setting the two lags and `leadTime` to `0` gives the camera that carries its subject's motion on the frame it happens. `rig:tracking()` answers how the camera follows right now: `lag` (how far the subject stands from the framed point), `lead`, `velocity` (the subject's, as the rig measures it), `recentering`, `idle` (seconds since look input) and `lookHeld` (a look the player made holds the heading while the subject stands).
```luau
local rig = entity(camId).component.get("cameraRigs.third_person_follow")
rig.verticalLag = 0.4 -- ease stairs and jumps more
rig.recenterDelay = -1 -- keep the heading the player leaves it at
rig:recenter() -- and turn it behind the subject on a button
```
## The control scheme
`inputMap` is the scheme the rig answers to. It reads two controls from it, each on its own:
- `look` — turns `aimYaw` and `aimPitch`.
- `zoom` — steps `cameraDistance`.
A map declaring only one of the two gives the rig that one and keeps the other where it is; the rig logs which control the map left out, and names the map. A field naming no map leaves the rig answering nothing, and logs that too. Point `inputMap` at a world's own map to rebind looking and zooming without touching this component.
**Repointing it on a live rig takes on the next frame.** The map the rig was holding is stood down — its controls leave the live set and its touch buttons leave the screen — and the map named here is taken up in its place:
```luau
entity(rigId).component.get("third_person_follow").inputMap = asset.resolve("mygame.input.cinema", "inputMap")
```
Assigning the map the rig already holds changes nothing, so re-stating the scheme leaves the live set where it is. While gameplay is paused the rig holds no map at all — the editor's camera has the controls — and it takes whatever `inputMap` names when play resumes.
```luau
local cam = entity(id).component.get("Camera")
cam.behavior = asset.ref("cameraRigs.third_person_follow", "component")
entity(id).component.get("cameraRigs.third_person_follow").cameraDistance = 3
```
## The camera pulls in when a collider is in the way
Each frame the rig sweeps a sphere of `cameraRadius` from the shoulder point beside the subject itself (wherever the framed point lags) out to where its framing puts the camera, and stands the camera where the sphere first meets a collider. Every collider in the world stops that sweep, whether or not anything draws it: an invisible walk bound (a `BoxCollider` with no `Model`), a trigger volume and a solid wall all pull the camera in alike. The follow subject is the one entity the sweep passes by default.
The pull-in never cuts. Sweeps of that line ahead, from where the subject is moving to and along where the line is turning over the next 0.8 s, bring the camera in ahead of a wall end or a pillar about to come between it and the subject, at the speed that has it clear when the line gets there; only something no sweep could see coming (a wall that appears) brings it in on the frame it blocks the view, so no frame is drawn from behind geometry. The camera stands no nearer the sweep's start than 0.4 m while there is room round it: when the line has less room than that (the subject against a wall or a pillar the camera is behind), the camera turns round the subject about its up to the nearest turn that has the room, keeps looking the way its framing looks, and turns back onto the line once the line has the room again. A start touching a collider is swept with a thinner sphere, which slides along it, a start nearer it than the thinnest sphere has room for by a ray, and a start inside one holds the camera as far out as it stood.
So a camera that snaps in close to the player, or collapses onto it, while nothing visible stands behind the player is meeting a collider nobody can see. Two fields settle it:
- `cameraIgnore` lists the entities whose colliders the camera sees through. Name the walk bounds and gameplay volumes there and the sweep passes them as it passes the subject, while walls the player can see still pull the camera in. Each entry is an entity (or its id), and it is the collider's own entity that is listed.
- `cameraRadius = 0` turns the pull-in off: the camera stands where its framing puts it, through every collider.
```luau
local rig = entity(camId).component.get("cameraRigs.third_person_follow")
rig.cameraIgnore = { entity.find("NorthBound"), entity.find("SouthBound") }
-- or drop the pull-in entirely
rig.cameraRadius = 0
```
## Thin occluders and the subject's body fade instead of filling the view
In play the camera fades what would otherwise fill the view in place of the subject. A thin occluder (a pillar, a pole, a post, a railing, a doorframe's jamb, a tree trunk: a collider no wider than `occluderFadeWidth` across the line from the camera to the subject at its narrowest, and no deeper along it) does not pull the camera in: the sweeps pass it, and while it stands between the camera and the subject it fades to `occluderFade`, that share of its pixels left undrawn in a screen-space dither so the subject shows through. Walls, floors and every collider wider or deeper than that still pull the camera in, as above. The subject's own body fades as the camera comes within `bodyFadeDistance` of the aim point, reaching `bodyFade` at the nearest the camera stands (0.4 m), so a camera pulled in against a wall shows what lies past the subject rather than the back of its head. Each fade eases in and out over `fadeTime`, never in one frame.
A fade covers the entity and its descendants, in this engine's own views (each player's camera sets its own), and shadows stay whole. `fadeIgnore` lists entities the camera never fades: they pull it in whatever their size. `occluderFade = 0` brings back the pull-in for every collider, and `bodyFade = 0` keeps the body drawn whole. `rig:fading()` reports what the camera fades this frame, and `renderer.drawStats().cameraFaded` how many renderables carry a fade.
```luau
local rig = entity(camId).component.get("cameraRigs.third_person_follow")
rig.fadeIgnore = { entity.find("GateLever") } -- a lever the player must always see
rig.occluderFade = 0 -- or pull in for every collider
```
## Attach through `Camera.behavior`
The Camera owns the behavior slot, so assigning the rig there is what lets the Camera tell it when `follow` changes. A rig added straight onto the entity with `component.add` still poses, but the Camera does not know about it and a `follow` assigned afterwards will not reach it.
Assigning the slot attaches the rig to the camera's entity, so it is tuned on that instance: `component.get("third_person_follow")` and set its fields. A `component.add("third_person_follow", { ... })` after the assignment, in a scene `build.luau` or anywhere else, writes its values onto the instance the slot attached and returns it, so the Camera keeps the one rig it knows about. In a `build.luau` that add is the way to tune the rig: its values are saved with the scene and the loaded rig holds them.
## Player cameras: leave `follow` unset
Entering play drops and respawns `PlayerPrototype` subtrees, so the body is recreated with a NEW entity id. A `follow` authored on the rig keeps pointing at the original, which is no longer live, and the camera freezes at its last pose instead of tracking the player.
For a player camera, set the target on the **Camera** and leave the rig's own `follow` empty:
```luau
entity(rigId).component.get("Camera").follow = body -- PlayerPrototype rebinds this on every spawn
```
`PlayerPrototype` refreshes `Camera.follow` to the live body each time it clones, and the rig reads that slot whenever its own `follow` is empty. Set the rig's `follow` only for a camera that watches a fixed, non-respawning subject.
# look
Turns the rig around what it is framing, while the right button is held, the
right touch zone is dragged, or the right stick is pushed.
# move
Pans the rig across the world it is looking at.
# zoom
Moves the rig toward and away from what it is framing.
# CharacterController
> 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.
Kinematic mover. Integrates velocity against gravity, walls, ceilings and
ground, and writes the result to the entity's position every frame.
It is the body's mover: its `.metadata` carries the `bodyMover` tag, which the
velocity verbs (`Physics.setVelocity`, `Physics.addVelocity`,
`Physics.getVelocity`, `Physics.moverOf`), the avatar on the body and a headset
reach it by. A movement component of your own (a vehicle, a hovercraft, a
jetpack) that carries the same tag takes its place on the body, or moves it in
turn with this one: of several movers on one body the enabled one moves it.
The physics guide's "Movers" section (`man topics/physics`) has the contract.
## Driving it
The character moves on a public input bus: `inputX`, `inputZ`,
`inputJump` and `inputJumpHeld`. Each frame the controller reads the bus, moves on what it found,
and then refills it for the next frame.
**Only the local player's body answers the player's controls.** The character
the local player is bound to (`layers.active.players.localPlayer.avatar`)
refills its bus from the `move` axis and the `sprint` / `jump` actions of its
input map, so the map drives it whenever nothing else does. Every other
character holds no map and refills its bus with no movement: an NPC, a
mannequin, a preview or another player's body stands where it is until
something writes its bus. The player's spawn binds the body for you; to hand
the controls to a character you made, bind it:
```luau
layers.active.players.localPlayer.avatar = entity(bodyId)
```
The character takes the map up on the frame after the bind and gives it back
when the binding moves to another body.
Anything else takes the character over by writing those three fields from its
own `update()` — an AI brain, a networked peer, a replay, or gameplay code
that wants the character committed during an attack. The write works from
**any** `executionOrder`, because the refill happens after the read: whatever
is in the bus when the controller next reads it is what the character does.
On the local player's body the controller fills the bus from the map once
more just before the read, so a press moves the body on the frame it
arrives, and that fill takes only the fields nothing has written since the
last refill. A write counts whatever value it carries
(`ref:fieldWrites(name)`), so a writer that holds the body still by writing
no movement and the jump let go keeps it still through every press.
- A writer ahead of the controller (`executionOrder` below `-100`) is acted on
the same frame.
- A writer behind it is acted on the next frame.
- A writer that writes some of the fields leaves the others to the map: one
that steers with `inputX` / `inputZ` alone leaves the jump to the player's
jump control, which jumps on the frame it is pressed.
- Stop writing, and the character stops one frame later; on the local
player's body the map has it back instead.
- Pausing gameplay empties the bus, so a character frozen mid-stride stands
where it was paused and a writer that had it committed says so again.
`inputX` / `inputZ` are a world-space velocity in units per second, the walk
the character is asked for: the controller takes its walk toward them at its
`acceleration` and `braking` (see "Movement feel" below), so scale them
yourself rather than expecting `moveSpeed` to. `inputJump` asks for one jump
and the next update consumes it. `inputJumpHeld` says the jump control is
held: write it `true` on every frame the jump is held, and a jump asked for
with it is cut short when it stops (with `minJumpHeight` above 0), on the
step it takes off when it stopped while the request waited in the
`jumpBuffer`; a jump asked for without it rises its full height.
A component that walks the character due north, whatever the input map says:
```lua
-- Northbound.component/init.luau
declare { executionOrder = 50 } -- anywhere works; 50 runs after the controller
public = {
speed = Field.number(4.0, Sync),
}
function update(_dt: number)
local cc = public.entity.component.get("CharacterController")
if cc == nil then return end
cc.inputX = 0
cc.inputZ = -public.speed
end
```
`WASDInput` is the same pattern shipped as a component: it reads an input map
of its own and writes the bus of whatever component `targetComponent` names,
which is how a mover that reads no controls of its own gets driven. On a
CharacterController — which reads `move`, `sprint` and `jump` from its own
`inputMap` — a WASDInput writes the bus every frame at its own `speed`, and
that is the speed the character walks at. `CharacterController.install` adds
one when `input = true` asks for it.
## The control scheme
`inputMap` is the scheme the character answers to. It reads three controls from it, each on its own:
- `move` — an axis2, projected against the active viewport camera so "forward" is into the screen. The camera turns for the frame in its look phase, before the controller reads it, so a look that turns the camera turns the walk on the same frame.
- `sprint` — held, multiplies `moveSpeed` by `sprintMultiplier`.
- `jump` — pressed, asks for one jump.
A map declaring only some of the three drives the character with those: a scheme with no `sprint` holds one gait, a scheme with no `jump` stays on the ground. The character logs which controls the map left out and names the map, so a game with three verbs ships a three-control scheme. A field naming no map leaves the character answering nothing, and logs that too.
**Repointing it on a live character takes on the next frame.** The map the character was holding is stood down — its controls leave the live set and its touch buttons leave the screen — and the map named here is taken up in its place:
```luau
entity(bodyId).component.get("CharacterController").inputMap = asset.resolve("mygame.input.run", "inputMap")
```
Assigning the map the character already holds changes nothing, so re-stating the scheme leaves the live set where it is. While gameplay is paused the character holds no map at all (the editor's camera has the controls), and it takes whatever `inputMap` names when play resumes. A character that is not the local player's body holds no map either, and takes whatever `inputMap` names when it is bound as that body.
## Movement feel
How the character starts, stops, turns, jumps and falls is set by its feel
fields. The same settings drive the package's character module
(`CharacterController.attach` / `Velocity.resolve`), through one set of rules
(`movement.feel` of `characterController.module`).
On the ground:
- `acceleration` (m/s², default 20) is how fast the walk speeds up toward the
walk asked for. At 20 a 2.5 m/s walk is reached in 0.125 s and a 7 m/s
sprint in 0.35 s.
- `braking` (m/s², default 30) is how fast it slows: to a stop when nothing is
asked, down to a slower walk, and away from a heading the request turned
from. A turn sheds the old heading at `braking` while it builds the new one
at `acceleration`, and a reversal at speed brakes to a stop before it speeds
up the other way, rather than flipping in a frame.
- Either at 0 reaches the walk asked for on the frame it is asked, which is
how the `instant` preset keeps a character that answers with no ramp.
- The walk is the character's own, on top of what carries it: on a belt or a
moving deck it speeds up relative to the surface; on a slope it follows the
ground. `velocityX` / `velocityZ` read the ramp as it happens, so
`Locomotion` blends its gait from the speed the body really moves at, and a
networked peer sees the motion the owner simulated.
The jump:
- `jumpHeight` (m) and `jumpApexTime` (s) state a jump directly: with both, a
full jump rises exactly `jumpHeight` and tops out `jumpApexTime` after
take-off, at any frame rate. `jumpHeight` alone rises that high against the
character's gravity; `jumpApexTime` alone takes off at `jumpForce` and tops
out that long after. At 0 (the default) a jump takes off at `jumpForce` m/s
against the character's gravity.
- `minJumpHeight` (m) above 0 makes the jump control's release cut the jump
short. Let go at take-off, it rises `minJumpHeight`; let go during the rise,
it rises `minJumpHeight` above where it was when let go; held to the top, it
rises the full height. A real tap holds the control a few frames, and a fast
jump has risen some way by then: a `minJumpHeight` of 0.8 m on a jump taking
off at 8.3 m/s gives a 0.05 s tap a hop near 1.3 m. Set `minJumpHeight`
below the hop a tap should give; the presets set it so. On the local player's body the input
map's `jump` control holds it (keyboard, gamepad and touch alike); a writer
of the bus holds it with `inputJumpHeld`, and the module with
`CharacterController.jump(id)` until `CharacterController.releaseJump(id)`.
- `fallGravityMultiplier` (default 1) scales gravity while the character falls,
from the top of a jump or off a ledge: above 1 a jump rises floaty and comes
down fast, below 1 it drifts down.
- `maxFallSpeed` (m/s) above 0 caps the fall.
- One request is one jump. `inputJump = true` (or one press of `jump`) spends
one jump, and `jumpCount` counts it. A character with `maxJumps = 2` jumps
once on the request and keeps its second jump for the next request it gets
in the air. Landing gives every jump back.
- `coyoteTime` (s) is how long after walking off the ground the first jump is
still the jump from the ground. Past it that jump counts as spent, so with
`maxJumps = 2` a request in the air takes the air jump, as it does after a
jump from the ground.
- `jumpBuffer` (s) keeps a request made in the air with no jump left, which
jumps the moment the character lands; the jump it takes closes the buffer.
A tap made just before landing takes off as a tap: with `minJumpHeight` set
it gives the short hop.
- In the air the velocity across the ground carries on and turns toward the
walk the bus asks for at `airControlFactor * 10` of the way a second. A run
held through a jump keeps its speed, so a 5 m/s running jump of about a
second covers about 5 m; letting go of the stick slows the character the
same way, and a new heading takes over gradually. The higher the factor the
faster it answers: at 6 or more it takes the asked-for walk within one 60 Hz
frame, and at 0 it keeps the take-off velocity untouched.
Four presets set every feel field at once. Apply one to a character, or name
it in `CharacterController.install(id, { preset = "weighty" })`:
```luau
preset.apply("characterController.presets.weighty",
{ entity = id, component = "CharacterController" })
```
| Preset | Ground | Jump |
|--------|--------|------|
| `instant` | no ramp: starts, stops and turns the frame it is asked | `jumpForce` against gravity, full height however it is pressed, no fall scaling or cap |
| `responsive` | 40 m/s² up, 50 m/s² braking: quick and crisp | 1.3 m in 0.38 s, let go at take-off 0.25 m, falls at 1.6x, capped at 20 m/s |
| `weighty` | 6 m/s² up, 6 m/s² braking: a heavy body that commits to its heading | 0.8 m in 0.36 s, full height every press, falls at 2x, capped at 25 m/s, little air control |
| `floaty` | 25 m/s² up, 15 m/s² braking: light, slides a little into stops | 2.5 m in 0.6 s, let go at take-off 0.3 m, drifts down at 0.6x, capped at 6 m/s, strong air control |
Each field can be set on its own afterwards, on top of a preset:
```luau
local cc = entity(id).component.get("CharacterController")
cc.jumpHeight, cc.jumpApexTime = 1.5, 0.45 -- a full jump: 1.5 m, top at 0.45 s
cc.minJumpHeight = 0.4 -- let go at take-off: 0.4 m
cc.fallGravityMultiplier = 1.8 -- comes down faster than it went up
```
## Stairs and steps
A grounded character walks up a riser or curb no taller than `stepHeight`
and down a drop no deeper than it. The capsule lands on the next tread in
the frame it reaches it and keeps that exact height, so the walls, the
ground and every query see the character where it stands.
What the player sees climbs smoothly: the character's direct children that
hold no collider and no physics body, with none below them (the body mesh, a
name label) are drawn
shifted back by the riser and close on the capsule as a critically damped
spring of `stepSmoothing` seconds (default `0.1`: about three fifths of a
step in that time, nine tenths in twice it). A rise or drop the ground's
slope accounts for, on a ramp or a hill, is drawn as it happens; a
character placed by something else (a teleport, a respawn) is drawn where it
was placed. `stepSmoothing = 0` draws the body on the capsule every frame.
The character's module (`characterController.update`) smooths its steps by
the same rule, through `movement.stepSmoothing`.
## Platforms, belts and the contact filter
The character meets the surfaces content declares on colliders the way a
rigid body does. Its ground, wall and ceiling queries are cast for the
character's own entity as their mover (`Physics.raycast(..., { mover = id })`
and the same option on the shape casts), so the contact rules the physics
step applies to bodies apply to it too:
- **One-way platforms.** A collider whose `oneWay` points up holds the
character from above only: it jumps up through the platform from below and
lands on top of it, and walks through its sides.
- **Dropping through.** `Physics.passThrough(character)` drops it through the
one-way colliders it stands on (or, with a second argument, only those that
entity owns). It falls through under its own gravity and meets each again
once it is clear of it.
```luau
Physics.passThrough(player) -- drop through what it stands on
Physics.passThrough(player, platform) -- drop through this platform alone
```
- **Moving surfaces.** Standing on a collider whose `surfaceVelocity` moves (a
conveyor belt, a treadmill, an escalator) carries the character at that
velocity on top of its own walk. It keeps the carry as momentum when it
jumps or walks off, and air control (`airControlFactor`) takes it back
toward the walk it asks for.
- **Moving bodies.** Standing on a body that itself moves or turns (a lift, a
moving platform, a turntable, a raft, a ship's deck, a train car) carries
the character with it: each frame the point under its feet goes where the
body took it, and the character turns with the body's turn about up, with
its own walk on top. It rises and descends with a lift without leaving the
ground, and keeps the body's motion at its feet as momentum when it jumps or
walks off. In the air it goes on moving with that motion until it lands, the
way a crate thrown off the deck does: air control (`airControlFactor`) steers
its walk relative to it, so a jump in place on a moving deck comes down on
the spot it left, and a wall it meets in the air stops the part of it the wall
is in the way of. A kinematic body a script moves (`localPosition` writes,
`Physics.setVelocity`), a dynamic body the simulation moves and a transform
something animates all carry it alike. The body is read where the frame
draws it (`Physics.drawnPose`), and the character is seated on the ground as
drawn, so the two stay in step on screen at any frame rate and physics tick
rate. A body a script moves after this component's `update` (an
`executionOrder` above -100, or a task) carries the character on the next
frame. The momentum a kinematic body or an animated transform leaves the
character with is how fast it carried the feet over the last tenth of a
second (and at least the last six frames), however the frames fell against
the physics ticks, and a body that vanishes from under the character
leaves it the same. A character something else moves (a teleport, a
respawn, a script writing its position) rides nothing until it stands on
a body again. A move faster than 150 m/s over the frame
(`StatedWalk.TELEPORT_SPEED`), or longer than 2.5 m over a frame of any
length (`StatedWalk.PLACEMENT_DISTANCE`), places it: it stands where it was
put at rest, with none of the fall, jump, walk or carry it had where it was
taken from, and with no footing on the ground it left: until it stands
again it has no `coyoteTime` to jump from, so with `maxJumps = 1` a
character put in mid-air takes no jump there. A shorter, slower move
carries it (a room-scale step in XR, a script pushing it along), and its
fall and walk go on; writing back the position it
already stands at moves it nowhere. In a multiplayer session the
character states its pose relative to the kinematic or dynamic body it
rides, and through a jump off it until it lands (`multiplayer.setPoseFrame`,
read back with `multiplayer.poseFrame`): every other peer draws it on that
body where that peer draws the body, so a rider on another peer's moving
deck holds its spot there on every screen.
```luau
local lift = entity.spawn("lift")
lift.component.add("BoxCollider", { half = { 1.5, 0.1, 1.5 } })
lift.component.add("Physics", { kind = "kinematic" })
Physics.setVelocity(lift.id, 0, 1, 0) -- the character on it rides up
Physics.setAngularVelocity(lift.id, 0, 1, 0) -- and turns with it
```
- **The contact filter.** Give the character a collider with a `contactTag`
(a trigger capsule is enough) and `Physics.setContactFilter` answers its
pairs: a collider whose tag the filter answers `"ignore"` or `"sensor"`
with the character's tag is one the character walks through.
```luau
player.component.add("CapsuleCollider", { isTrigger = true, contactTag = "player" })
Physics.setContactFilter("player", "ghostWall", "ignore")
```
## Launching, knockback and momentum
Give the character speed it did not choose (a launch pad, a spring, a
knockback from a hit, a rope let go of, a respawn that sends it off) with
`setVelocity` or `addVelocity` on its controller, in m/s in world space. The
same verbs on `Physics` reach it too, so `Physics.setVelocity(player, ...)`,
`Physics.addVelocity(player, ...)` and `Physics.getVelocity(player)` work on a
character as on a rigid body. A character holds no mass, so an impulse is
given as the change of speed it makes (`addVelocity`), and
`Physics.applyImpulse` moves it nowhere and says so in the log.
```luau
local cc = entity(player).component.get("CharacterController")
cc:addVelocity(0, 14, 0) -- a jump pad: straight up, 10 m high at 9.81 m/s²
cc:setVelocity(6, 10, 0) -- a launch pad: thrown up and along +X
cc:addVelocity(away.x * 8, 4, away.z * 8) -- knockback away from a hit
Physics.addVelocity(player, 0, 14, 0) -- the same through Physics
local v = cc:getVelocity() -- { x, y, z }, world space
```
`setVelocity` replaces the velocity the character has; `addVelocity` adds to
it (to its walk, its fall and any motion kept from a body it left). Called
several times before the character's next frame, `setVelocity` calls replace
one another and `addVelocity` calls add up, on top of the last `setVelocity`.
Either takes effect on the character's next frame, after anything that
placed it this frame, so a respawn onto a launch pad launches. Each takes
`(x, y, z)`, a `vector` or a table `{ x, y, z }`, and answers `true`.
The controller carries the velocity on through its own movement, the way it
carries a jump or the motion of a platform it leaves:
- **Standing, with no speed up**, the part across the ground is the
character's walk: `braking` slows it to a stop (or to the walk its input asks
for), so 6 m/s with a `braking` of 5 slides 3.6 m. Walls stop it a skin short
of their face and slide it along them, and a dynamic body in the way is
pushed as a walk pushes it.
- **With any speed up**, it leaves the ground on that frame and reads
`grounded` false until it lands. No jump is spent, and the jump it could
have taken from the ground in `coyoteTime` is gone, so a character with
`maxJumps = 2` has its air jump and one with 1 has none. It rises and falls
under its gravity (a launch rises its full height whether the jump control
is held or let go), a ceiling stops the rise, and on a moving body it adds
the body's motion as it leaves, as a jump does.
- **In the air**, the speed across the ground it was given flies on: air
control (`airControlFactor`) steers only the walk the input asks for, on top
of it, as it does over the motion kept from a platform. A wall met in the air
stops the part of it the wall is in the way of.
- **Landing**, what is left of it becomes the walk, and `braking` slows it on
the ground.
The movement is integrated exactly for each part of a frame, so a launch rises
the same height and lands the same distance away at 30 and at 120 frames a
second, within the step of the frame it lands on. On a body the character
stands on, the velocity is relative to that body. In a multiplayer session the
peer that moves the character applies it (the owner of a player's body, or
the peer it is bound to) and every other peer sees the motion through the
character's replication. On another peer's replica both calls leave the velocity
as it is and answer `false` (`Physics.setVelocity` and `Physics.addVelocity`
say so once in the log), so a hit landed on another player's body is sent to
the peer that moves it (a `Sync` event or `multiplayer.send`) and given there.
## Other characters
Characters meet one another as solid bodies. Every entity carrying a
`CharacterController` is an upright capsule of its `radius` and `height` to
every other character's wall pass (`physics.characters`), so two characters
walking into each other stop a skin apart, a character meeting another off
centre slides around it, and `blocked` reads true while a walk presses into
another character. The same holds for the local player, an NPC and another
player's body.
A character is a body while its entity is active and its controller enabled:
one set inactive (`entity(id):setActive(false)`) or with its controller
disabled (`enabled = false`) lets the others walk through it until it is
switched back on.
The push rule:
- A walk never moves another character. Each peer moves only the characters
it owns, against where it sees the others, so two players' bodies meet on
both peers' screens.
- Two characters that overlap (placed into one another, two spawned at one
point, a body the network shows a frame late) move apart at up to 2 m/s
each, each taking half of the overlap, and never through a wall. A pair
pressed together stands still a skin apart.
- A character gives way to no body moving into it: the one walking in is the
one stopped, on the peer that moves it, so a player walking into a standing
one never drives it along, however late each peer sees the other.
- Only bodies sharing some height meet: a character jumping over another
passes above it, and one coming down onto another's head is moved off it to
the side.
Which characters pass through which is the contact filter's to say, by each
character's `contactTag` (`"character"` unless content names another):
```luau
Physics.setContactFilter("character", "character", "ignore") -- nobody blocks anybody
ghost.component.get("CharacterController").contactTag = "ghost"
Physics.setContactFilter("ghost", "character", "ignore") -- the ghost walks through people
Physics.setContactFilter("redTeam", "redTeam", "ignore") -- teammates pass, foes block
```
## Triggers, pickups and the bodies it walks into
The character holds no rigid body: it states its capsule (`Physics.setWaterVolume`),
`height` tall and `radius` round, standing on its feet. That capsule is how
the rest of the world meets it:
- **Triggers and pickups.** A trigger collider hears the character enter and
leave it as it hears a body (`Physics.onTrigger(zone, fn)`, with `other`
the character's entity), and a listener on the character
(`Physics.onTrigger(character, fn)`) hears every trigger it goes through.
Every engine the character exists in hears it, the remote players' bodies
included, so a zone counted on each peer counts every player. A trigger on
an entity beneath the character (a sensor it carries) rides with it and
does not hear it.
- **Water.** `Physics.onWater` hears it go in and out of the water and
`Physics.immersion` reads how deep it stands.
- **Pushing.** A dynamic body the walk runs into is pushed along the walk:
the walk stops at it as at a wall, and the body is given the impulse that
brings its speed along the walk up to the walk's, with at most `pushForce`
newtons (400 by default) behind it. On level ground a body moves once
`pushForce` passes its friction coefficient times its weight, so at the
default a 5 kg crate goes along at the walk with the character behind it and
a 500 kg one stands like a wall. `pushForce = 0` makes every body a wall.
- **Bodies moving into it.** A body that moves into the character puts it
back outside, as a wall that moved into it does.
```luau
local player = layers.active.players.localPlayer.avatar
Physics.onTrigger(coin, function(e)
if e.kind == "enter" and e.other == player.id then collect(coin) end
end)
player.component.get("CharacterController").pushForce = 150 -- a weaker shove
```
## Telemetry
These read back what the mover did on the frame just simulated:
- `grounded` — standing on ground no steeper than `maxSlopeAngle`.
- `falling` — in the air and descending.
- `sliding` — on ground too steep to stand on, being carried down it.
- `blocked` — the character asked to move horizontally and the wall pass left
it with none of that movement: pressed into a wall, or wedged where two
surfaces meet. This is what tells a character standing still apart from one
whose walk is being refused.
- `slopeAngle` — the angle, in degrees, of the ground under it.
- `velocityX` / `velocityY` / `velocityZ` / `horizontalSpeed` — its velocity,
across the frame it stands in (`frame`). `getVelocity()` reads it in world
space, with any velocity given since its last frame.
- `jumpCount`: jumps used since it last landed. Walking off a ledge counts
the jump from the ground as used once `coyoteTime` has passed.
## Standing still
A character standing on the ground with nothing asking it to move rests: it
takes no movement step and writes none of its fields, so a crowd of idle
characters costs little more than the check each one makes that nothing has
reached it. It takes its step again on the frame anything does: a write to its
input bus or any of its fields, its feet moved by something else, the ground
or the body it rides moving or changing (taken away, switched off, passed
through, its surface set moving), a collider coming to overlap it, another
character moving within reach, the gravity at its feet changing, or its being
bound as the local player's body. Entities spawned and despawned elsewhere in
the world leave it resting. Telemetry reads what it read on the frame it came
to rest.
`stats()` reads how its frames went:
```luau
local s = entity(id).component.get("CharacterController"):stats()
print(s.resting, s.stepFrames, s.restFrames)
```
# bodyFacing
> 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.
Which way a character's body visibly faces, by the one rule every reader of
that facing shares. `Locomotion` and `LocomotionFull` resolve the anchor they
turn through here, and `CameraRig.visibleForward` reads the facing through
here, so a follow camera binding behind a character reads the anchor the
component turns, whichever component animates it and however the character's
children are ordered (a body swapped in by `setCharacter` stands after the
avatar's name label).
The rotation anchor is the topmost direct child of the entity the component
sits on whose subtree holds the rigged skeleton, else that entity itself when
it carries a Skeleton. Each component declares which way along the anchor the
body faces: `Locomotion.forward` is a direction in the anchor's local frame
(`{0, 0, -1}` by default, the -Z every composed avatar body faces along), and
`LocomotionFull.faceSign` names the anchor's -Z (`1`) or +Z (`-1`).
How a body file is composed under the anchor so it faces the anchor's -Z,
measured from its skeleton, is `@builtin::modules.bodyFacing`.
## Exports
- `BodyFacing.COMPONENTS`: `{ "Locomotion", "LocomotionFull" }`, the
components that turn a body, in the order a character carrying both reads
them.
- `BodyFacing.isRigged(entityId) -> boolean`: the entity carries a Skeleton
whose rig has hydrated (bones present).
- `BodyFacing.body(entityId) -> string?`: the skinned body, the entity itself
when rigged, else its first rigged descendant.
- `BodyFacing.anchor(entityId) -> string?`: the rotation anchor of the
character the facing component sits on.
- `BodyFacing.heldAnchor(entityId) -> string?`: the anchor as `anchor`
resolves it, kept from one read to the next while it still stands as the
entity or one of its direct children, and resolved again once it has gone,
so a reader asking every frame walks the body's subtree once.
- `BodyFacing.declared(componentName, component) -> (x, y, z)`: the
anchor-local direction a facing component declares.
- `BodyFacing.declaring(targetId) -> (id?, componentName?, component?)`: the
subject or the nearest ancestor carrying a facing component.
- `BodyFacing.forward(targetId) -> (x?, y?, z?)`: the world-space direction
the body faces, read through `heldAnchor`, nil when nothing up the chain
turns the subject.
- `BodyFacing.source(targetId) -> string?`: what `forward` reads the facing
from (the declaring entity, the component, the anchor and the anchor-local
direction it declares), as one key that changes when a facing component
arrives or goes, when what it declares changes (`Locomotion.forward`,
`LocomotionFull.faceSign`) or when a body stands up under the character,
and holds while the body turns; nil when nothing up the chain turns the
subject.
```luau
local BodyFacing = require("characterController.characterController.movement.bodyFacing")
local fx, fy, fz = BodyFacing.forward(characterId)
```
# MovementState
Component that exposes movement state for controller-driven animation and gameplay consumers.
# vehicleController
> 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.
`VehicleController` drives a car built from `WheelCollider`s: throttle,
steering, brakes, a handbrake, boost and recovery, with arcade assists (steering
help, traction control, air control) that tune from forgiving to simulation. It
reads its intent from the player through the `vehicle` input map (keyboard,
gamepad and touch), or from a script (`controlSource = "script"`,
`setIntent { throttle, steer }`) for traffic and AI drivers. It carries the
`bodyMover` tag.
| Asset | What it is |
|---|---|
| `VehicleController` | The driver component, on the chassis entity. |
| `vehicleIntent` | `require("vehicleController.vehicleIntent").vehicle(opts)`: the driving intent read from an input map, for a hand-written driver. |
| `inputMaps.vehicle` | throttle (W/S), steer (A/D), brake (Space), handbrake (Ctrl), boost (Shift), recover (R), interact, zoom (wheel), with gamepad and touch bindings. |
```luau
car.component.add("vehicleController.VehicleController", { camera = cam.id })
car.component.get("vehicleController.VehicleController"):takeControl()
```
With the `cameraRigs` package beside it (the Controllers world installs both),
the zoom control moves a `chase` camera named in `camera`.
`documentation/driving` builds a whole drivable car.
# characterController
The character controller of the Controllers world. `CharacterController`
moves a character with capsule casts: walking, running and jumping, coyote time,
slopes, steps, moving platforms, carrying, pushing and swimming. `MovementState`
states the motion its animation reads, and `Locomotion` (or the 87-clip
`LocomotionFull`) plays the Synty Polygon Masculine clips this package holds
from it. `WASDInput` drives a controller from the keyboard, and the
`characterController` toolbox installs the set on an entity.
`CharacterController` carries the `bodyMover` and `playerDefault` tags and
`MovementState` carries `playerDefault`, so a default player authored once the
package is installed walks with them. The player's controls drive the
character once it is bound as the local player's body
(`layers.active.players.localPlayer.avatar = entity(id)`); any other
character moves on what writes its `CharacterController` input bus.
Installed as `@controllers` (`world.installLibrary({ world =
"034d26cf-dc3d-4123-abad-3944f97c6a60", as = "controllers" })`), its assets are
`characterController.<name>`.
## Layout
```
characterController.package/
CharacterController.component -- the mover
MovementState.component -- the motion the animation reads
Locomotion.component -- blend-space animation (synty preset)
LocomotionFull.component -- the 87-clip variant (synty_full preset)
WASDInput.component -- keyboard drive of a controller's input bus
AnimDebug.component -- an overlay of the controller's state
characterController.module/ -- install / uninstall / preset, and the
-- collision and movement helpers
presets/ -- feel presets and the Synty clip presets
files/synty/ -- the Synty body and its animation clips
inputMaps/flight.inputMap -- flyUp / flyDown for a flying player
tools/characterController.toolbox/ -- install and uninstall tools
documentation/ -- 01-overview to 05-launch-and-knockback
```
## Flow
```
┌────────────────────┐
user / agent ──┤ characterController│
│ .toolbox │
└────────────────────┘
│
▼
┌──────────────────────┐
custom code ──────┤ characterController │── install /
(require) │ .module (API) │ uninstall / preset
└──────────────────────┘
│
▼
┌────────────────────────┐
│ CharacterController │
│ + Locomotion │
│ + MovementState │
│ + AnimDebug │
│ (+ third-person cam) │
└────────────────────────┘
│
▼
WASD-driven character with animation
on any entity, no hand wiring required.
```
`characterController.install(entity, opts)` is the only thing most callers
need — it adds the controller, the locomotion graph, the movement-state
mirror, and (optionally) a third-person camera child. The package is
self-contained: it depends only on standard utility modules and on the
animation graph engine, never on game-specific code.
## The engine's locomotion contract
`Locomotion` and `LocomotionFull` carry the `locomotion` tag in their
`.metadata`, and the `synty`, `synty_full` and `humanoid` presets carry it as
clip sets for them. The engine reaches a body's locomotion through that tag
(`@builtin::modules.api.engine.body_locomotion`): an avatar's composition
states the way its body faces, a body swap rebuilds its graph, and the avatar's
animator, a headset body and a carried prop read its facing. The `synty`
preset also carries `playerDefault`: it is the clip set every humanoid avatar
in a world holding this package animates with when it names none.
## Documentation
- [`documentation/01-overview.md`](documentation/01-overview.md) — what
this package is and when to reach for it.
- [`documentation/02-install.md`](documentation/02-install.md) — the
`characterController.install(id, opts)` recipe.
- [`documentation/03-presets.md`](documentation/03-presets.md) —
shipped presets (synty, default humanoid) and authoring your own.
- [`documentation/04-customize.md`](documentation/04-customize.md) —
overriding components, swapping the camera, custom blend spaces.
# characterController
> 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.
Physics-based character controller — capsule movement with
ground / wall / ceiling detection. A kinematic controller using
raycasts for collision; handles gravity, jumping, slope traversal,
step climbing, wall sliding, coyote time, and riding the bodies it stands on
(`physics.platform`). The
module owns a per-entity registry; attach once, call `move` / `jump`
each frame, then drive a per-frame `update(dt)`. The
`install` / `uninstall` / `preset` surface wires up the standard set
of components (CharacterController + Locomotion + MovementState +
optional WASDInput and third-person camera child) in one call.
Require it to use the surface:
```luau
local CharacterController = require("characterController.characterController")
```
## Exports
- `CC.attach(entityId: string, userConfig: Config?)` — register an entity, merge user overrides over `Defaults.standard`.
- `CC.detach(entityId: string)` — drop the registry entry.
- `CC.move(entityId: string, direction: Vec3)` — set per-frame world-space movement input (`y` is ignored).
- `CC.jump(entityId: string)` — request a jump; honours coyote time and jump buffer.
- `CC.getState(entityId: string) -> State` — snapshot copy of grounded / falling / velocity / etc.
- `CC.getVelocity(entityId: string) -> (number, number, number)` — current `vx, vy, vz`, with any velocity given since the last update; for an entity carrying the `CharacterController` component, that component's.
- `CC.setVelocity(entityId: string, x: number | Vec3 | vector, y: number?, z: number?) -> boolean` — replace the character's velocity (m/s, world space): a launch pad, a knockback. Standing with no speed up it is walk `braking` slows; with speed up it leaves the ground and flies, air control steering only the walk asked for on top of it, and on landing what is left is braked. Takes effect on the next update, after a placement.
- `CC.addVelocity(entityId: string, x: number | Vec3 | vector, y: number?, z: number?) -> boolean` — add to the character's velocity, an impulse as the change of speed it makes; calls before the next update add up. Both reach a body this module moves (`attach`) and one carrying the `CharacterController` component (`install`), answer false on another peer's replica, and raise for an entity with neither.
- `CC.setGravity(entityId: string, gravity: number)` — update gravity at runtime.
- `CC.setMaxSlope(entityId: string, degrees: number)` — update max walkable slope angle.
- `CC.setConfig(entityId: string, key: string, value: any)` — update a single config key.
- `CC.getConfig(entityId: string) -> Config` — config copy.
- `CC.update(entityId: string, dt: number)` — advance one frame (resolve movement, write position, tick state machine). `dt` is clamped to 0.1. A body something else placed elsewhere since the last update (a teleport, a respawn, a script writing its position), faster than `StatedWalk.TELEPORT_SPEED` (150 m/s) or longer than `StatedWalk.PLACEMENT_DISTANCE` (2.5 m) over a frame of any length (`StatedWalk.placesCharacter`), starts from where it was put at rest, with no footing or coyote time to jump from until it stands again; one carried shorter and slower keeps its motion.
- `CC.isAttached(entityId: string) -> boolean` — whether the entity has a registration.
- `CC.install(entityId: string, opts: InstallOpts?) -> InstallResult` — high-level wire-up (components + optional camera / mesh / WASDInput).
- `CC.uninstall(entityId: string) -> UninstallResult` — remove everything `install` added.
- `CC.preset(entityId: string, presetName: string) -> PresetResult` — apply a preset to an already-installed character in place.
Types:
- `Vec3 = { x: number, y: number, z: number }`
- `Config = { height?, radius?, maxSlopeAngle?, stepHeight?, gravity?, jumpForce?, coyoteTime?, jumpBuffer?, maxJumps?, airControlFactor?, groundSnapDistance?, stepSmoothing?, skinWidth?, moveSpeed? }`
- `State = { grounded, falling, sliding, wallContact, wallNormal, velocity, groundNormal, slopeAngle, jumpCount, timeSinceGrounded, timeSinceWallContact, onMovingPlatform, platformEntity? }`
- `BundleRef = { guid?, __ref?, identity?, path?, name? }`
- `InstallOpts = { preset?, camera?, input?, mesh?, overrides? }`
- `InstallResult = { entityId, cameraId?, meshHostId? }`
- `UninstallResult = { entityId, despawned }`
- `PresetResult = { entityId, preset, applied }`
## Usage
```luau
local CharacterController = require("characterController.characterController")
-- Low-level: manual attach + per-frame drive.
CharacterController.attach(entityId, { gravity = -15, jumpForce = 7 })
CharacterController.move(entityId, { x = 1, y = 0, z = 0 })
CharacterController.update(entityId, dt)
-- High-level: one-call wire-up.
CharacterController.install(entityId, {
preset = "humanoid_default",
camera = true,
overrides = { jumpForce = 8 },
})
```
## Notes
- `attach` merges user config over `Defaults.standard`; passing
unknown keys is allowed (they survive into the config table).
- `update` clamps `dt` to 0.1s to prevent capsule tunnelling on
lag spikes.
- `getState` and `getConfig` return shallow copies — mutating the
result does not affect the controller. The returned `velocity` /
`wallNormal` / `groundNormal` are also shallow copies.
- `install` is idempotent per component — re-running on an already
wired entity adds nothing new. `uninstall` removes the components
and any third-person-camera child that targets this entity.
- `preset` mutates fields in place and never adds or removes
components — call `install` first.
# Locomotion
Blend-space-driven locomotion for entities running the
characterController package. Feeds a single 2D blend space (strafe-angle
on X, speed on Y) with idle / walk-{F,L,R,B} / run-{F,L,R,B} / sprintF
clips from the character's own walk.
The walk is what the character's `CharacterController` states each frame it
moves it: its walk across what it stands on, so a body carried by a conveyor,
a moving deck or a lift while it stands still plays its idle, and the walk it
is asked for. The body turns toward the walk it is asked for at whatever speed
it asks (a light stick push, a walk into a wall the walls refuse), and with
none asked toward its velocity once that is faster than `moveDeadzone`. A
body that carries neither a `MovementState` nor a `CharacterController` reads
the walk the nearest of its ancestors with a `CharacterController` states, so
a body parented under a root a controller walks idles on a conveyor and turns
toward a wall it is asked to walk into, as that root does. On a frame nothing
states the walk (another peer's avatar the sync moves, a body a script moves)
the velocity is measured: from the entity's `MovementState`, or its
`CharacterController` without one, against its parent; and on a body that
carries neither, from its position in the world, so a body parented under the
root an NPC's brain and navigation move walks and faces with that root.
The strafe angle is the signed angle from the body's facing to
its velocity, positive toward the body's right (`forward x up`): the R
clips sit at +90, the L clips at -90 and the B clips at 180. Each
clip's point sits at the speed the clip carries this body at: its
retarget bake measures how fast the ground passes under the
stance foot on this body's legs, so the feet move with the ground at
whatever speed the body moves. A clip that plays without a measured
speed sits at its gait's `walkSpeed` / `runSpeed` / `sprintSpeed`.
Pair on the same entity (or a parent of) a `SkinnedModel`. The
component creates the AnimGraph, polls for the SkinnedModel child
once start() has run, registers the clips as blend-space points and
plays the graph. `update()` damps speed + angle and writes them to
the active blend space each frame.
Once every clip has bound, the component hands the graph to the engine
(`AnimGraph:runNatively`): the engine reads the walk the mover states, or
measures the root's velocity from its position, turns the body as above, damps the speed and angle and evaluates
the blend space every frame, and the component's `update` is held. A body
the sync moves (another peer's avatar), an NPC and the local player's own
body all walk with no script running for their pose. The component takes
the graph back when one of its fields changes or another component changes
the graph (a layer spliced over it), and runs it in script while the graph
holds a node the engine does not run, a clip that drives blend shapes, or
its velocity is read from a `CharacterController` without a `MovementState`.
`component.get("Locomotion"):stats()` reads
`{ native, handle?, frames?, refusal?, motion, space }`: where the graph runs,
why not in the engine when it does not, whether the velocity is the walk the
mover stated (`motion = "stated"`) or a measured one (`"measured"`), and
whether a measured velocity is the body's motion against its parent
(`space = "local"`) or in the world (`"world"`).
## Facing in multiplayer
The body's facing is the rotation of its anchor, the child of the root that
holds the skinned body, and only the peer that owns the body turns it. The
component names that child with `multiplayer.syncChildPose`, so its local
pose travels with the synced root: every other peer draws the facing the
owner states, a short delay behind on the timeline the root is drawn on, at
join, after the body stops and through a turn in place alike (a script that
turns the anchor on the owner's peer is drawn turned everywhere). On a peer
that draws it so, `multiplayer.childPoseFromOwner(anchor)` reads true and the
component, in script or in the engine, reads its strafe angle from that
facing and leaves the anchor's rotation as the owner states it.
## Jumping, falling and landing
`jumpAnim`, `fallAnim` and `landAnim` are the air poses: the take-off and
rise, the fall, and the landing. With any of them set (the `synty` preset sets
all three, and the built-in humanoid avatar uses it) the blend space and those
clips sit under one Mixer, and the body moves between four states by the
motion of its root:
- **ground**: the locomotion blend plays.
- **rise**: the body is off the ground and moving up faster than 1 m/s. The
take-off clip plays from its start.
- **fall**: the body is off the ground and moving down faster than 1 m/s (a
walk off a ledge), or its rise has stopped. The fall clip loops.
- **land**: the ground is under the body again. The landing clip plays from its
start and fades into the locomotion blend over `landTime` seconds.
The body is off the ground while nothing stands within 5 cm below its feet
across its footprint. The footprint is the disc its `CharacterController`
stands on, its `radius` less its `skinWidth` (0.25 m without one), and the
5 cm are counted from the ground the feet stand a `skinWidth` above, so a body
standing on the edge of a ledge, or with a wide skin, reads the ground its
controller stands on. A sphere of the footprint's radius is swept down past
the colliders the character carries, far enough to reach an edge at the rim
of the footprint, and the surface it meets counts where the sphere touched it.
A change of the controller's `radius` or `skinWidth` reaches the sweep on the
next frame (the controller calls `footingChanged()`). A body on nothing that
moves neither up nor down (a preview, a mannequin) keeps the locomotion blend.
Each pose's weight moves toward its state's at
`1 / airBlendTime` a second. A slot left nil, or whose clip failed to bind, is
stood in for: the take-off by the fall, the fall by the take-off, and the
landing by the locomotion blend. A clip that failed to bind keeps the graph in
script, and `stats().refusal` names the clip.
The engine runs the air states with the rest of the graph, so the local
player, an NPC and another player's body the sync moves all jump, fall and
land the same way with no script running for their pose.
```luau
local loco = entity(id).component.get("Locomotion")
loco.jumpAnim = asset.resolve("A_Jump_Running_Masc", "animation")
loco.landTime = 0.2
```
# LocomotionFull
> 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 full Synty locomotion animation layer: 87 in-place clips (walk, run and
sprint in eight directions, crouching, starts, stops, turns on the spot, jumps,
falls and landings) driven by a five-state machine (locomotion, crouch, jump,
fall, idle) over a layered `AnimGraph`. Put it on a character's body in place
of `Locomotion`, beside the `CharacterController` that moves it and the
`MovementState` that states the motion it reads; the `synty_full` preset holds
its clip slots and speeds. Clips retarget from their source rig onto the
body's rig, so the set drives any humanoid body.
```luau
body.component.add("characterController.LocomotionFull", {})
preset.apply("characterController.presets.synty_full", { entity = body.id, component = "characterController.LocomotionFull" })
```
# flight.inputMap
Vertical movement for a player that flies or swims: `flyUp` and `flyDown`.
The map composes — activate it beside the standard scheme and the player
gains two controls, release it and they lose exactly those two. Its group is
`player`, so a vehicle or a menu that stands the player down stands these
down too.
- **flyUp** — `E` or `Space`, the right trigger, or a lower-right touch
button.
- **flyDown** — `Q`, `Ctrl` or `Shift`, the left trigger, or a lower-right
touch button.
A controller that wants a single signed value reads both and subtracts:
```lua
local map = self.flightMap:activate()
map.flyUp:onInput(function(_, dt, active) self.up = active end)
map.flyDown:onInput(function(_, dt, active) self.down = active end)
```