# 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" })
```
# 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)
```
# 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.
# 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)
```
# 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.
# 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)
```
# 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.
# cameraRigs
> In a world that installs the Controllers library (`world.installLibrary({ world = "034d26cf-dc3d-4123-abad-3944f97c6a60", as = "controllers" })`), every package name on this page is written with `@controllers::` in front of it, and `asset.list("component")` lists each one under that name.
Camera behaviors for games: a `Camera` names one in its `behavior` field and
the behavior moves and turns the camera every frame. Each carries the
`cameraBehavior` tag, so `layers.active.camera.behaviors` lists it once the
package is installed, and `orbital_follow` carries `playerDefault`, which makes
it the camera a default player is authored with.
| Behavior | What it does |
|---|---|
| `orbital_follow` | Orbits the player on three rings (low, middle, high); look turns it, the wheel zooms, and it pulls in past walls. |
| `third_person_follow` | An over-the-shoulder camera that sits behind the player and turns back behind them while they walk. |
| `first_person` | The camera at the player's eyes; seats in a `FirstPersonBody`. |
| `chase` | Trails a moving body from behind and above: a car, a boat, a runner. |
| `mount` | Rides a seat on a body: a cockpit, a hood, a turret sight. |
| `rts` | A strategy camera that pans, rotates and zooms over a map. |
| `isometric` | A fixed-angle isometric camera that pans and follows. |
| `birds_eye` | Looks straight down from overhead. |
| `orbit` | Orbits a point or an entity under the look and zoom controls. |
| `side_scroller` | Holds a 2.5D side view on a target. |
| `cinematic` | Plays a cutscene path. |
| `menu` | Holds the camera's authored pose. |
`camera_rig` is the module the follow cameras share (follow, trail, pull-in,
fades, recentring). The `cameraRig` input map binds move, look and zoom for the
`rts`, `isometric`, `birds_eye`, `orbit`, `chase` and `mount` behaviors; the
follow cameras read `@builtin::inputMaps.default`.
```luau
local cam = entity.spawn("cam")
cam.component.add("Camera", { behavior = asset.ref("cameraRigs.chase", "component") })
cam.component.get("cameraRigs.chase").target = car.id
```
`documentation/choosing-a-camera` says which behavior fits which game and the
fields each one reads. Every behavior runs looks through the player's own camera
settings (`@builtin::modules.api.engine.camera_settings`).
# movement
[[describe]] Say what the module provides and who calls it.
# 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.
# flyDown
Descends without changing where the player looks.
# flyUp
Rises without changing where the player looks.