# 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)
```
# feel
> 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 rules that give a character its feel, shared by the `CharacterController`
component and the package's character module (`Velocity.resolve` and the
state machine), so both answer the same settings the same way.
## Exports
- `Feel.DEFAULTS`: the feel a character has when nothing states another
(`acceleration` 20, `braking` 30, `jumpForce` 5, `jumpHeight` 0,
`jumpApexTime` 0, `minJumpHeight` 0, `fallGravityMultiplier` 1,
`maxFallSpeed` 0).
- `Feel.walk(vx, vz, wantX, wantZ, acceleration, braking, dt) -> (vx, vz, dx, dz)`:
the ground velocity after `dt` seconds of walking toward the request, and
the distance covered across the ground over them, exact for that motion. It
speeds up along the request at `acceleration`, slows at `braking`, sheds
the part across the request at `braking`, and brakes to a stop before a
reversal speeds up the other way. 0 for either reaches the request at once.
- `Feel.launch(settings, pull, held) -> (speed, rise)`: the take-off speed of
a jump and how it rises, from `jumpForce`, `jumpHeight`, `jumpApexTime` and
`minJumpHeight`, against the gravity `pull` (m/s², positive pulling down).
`held` says the jump was asked for with the jump control held, which makes
it one a release cuts.
- `Feel.release(vy, rise, held) -> (vy, rise)`: a jump asked for held, once
the control reads let go during its rise (on the step it takes off, for a
request let go before then), is cut to the speed that tops it out
`minJumpHeight` above where it was.
- `Feel.vertical(vy, dt, rise, pull, settings) -> (dy, vy, rise)`: one step
along up off the ground, integrated exactly: a rising jump against its own
gravity, a fall at `pull * fallGravityMultiplier`, no faster than
`maxFallSpeed`. A step crossing the top switches gravity there, so the stated
height and apex time hold at any frame rate.
- `Feel.jumpsAfter(jumpCount, maxJumps, footing) -> number?`: the jump count a
granted request leaves, or nil. On its feet or within coyote time
(`footing`) a character takes its first jump; past it the jump from the
ground counts as spent and a request takes the next jump `maxJumps` leaves.
## Usage
```luau
local Feel = require("characterController.characterController.movement.feel")
local dx, dz
vx, vz, dx, dz = Feel.walk(vx, vz, wantX, wantZ, 20, 30, dt)
local vy, rise = Feel.launch({ jumpHeight = 1.2, jumpApexTime = 0.4, minJumpHeight = 0.4 }, 9.81, true)
vy, rise = Feel.release(vy, rise, jumpHeld)
local dy
dy, vy, rise = Feel.vertical(vy, dt, rise, 9.81, { fallGravityMultiplier = 1.5, maxFallSpeed = 20 })
```
# statedWalk
How a body reads the walk its character's mover states, and which way that
walk turns it. `Locomotion` and `LocomotionFull` both read it through here, and
the engine running Locomotion's graph reads it by the same rule.
Each frame it moves a character, the `CharacterController` states its own walk
across what it stands on (its motion less the carry of the ground under it)
and the walk it was asked for (`__poseProgram.stateWalk`). A frame something
else moves the character (a script, a path, a teleport) states none, and the
body's motion that frame is its mover's velocity; a body with no mover of its
own (an NPC body under the root its brain and navigation move) measures its
motion in the world.
## Exports
- `StatedWalk.motion(body, ms, cc, measured, dt) -> (vx, vy, vz, askedX?, askedZ?)`:
this frame's motion across the frame `body` stands in: the stated walk
whenever a mover states one, else the velocity of the entity's
MovementState, else of its CharacterController, else the motion measured in
the world (`measure`); the velocity along up; and the walk asked for, nil
when nothing stated one.
- `StatedWalk.measured() -> Measured`: a fresh record of a body's measured
motion, which the component animating the body keeps.
- `StatedWalk.measure(body, measured, dt) -> (vx, vy, vz)`: the body's world
position's step since the frame before over the frame's gameplay seconds,
across its standing frame. A step faster than `StatedWalk.TELEPORT_SPEED`
(150 m/s) is a placement and leaves the velocity as it was.
- `StatedWalk.isPlacement(dx, dy, dz, dt) -> boolean`: whether a step over
`dt` seconds is faster than `StatedWalk.TELEPORT_SPEED`.
- `StatedWalk.placesCharacter(dx, dy, dz, dt) -> boolean`: whether a move
something else gave a character over a frame placed it rather than carried
it: a move faster than `StatedWalk.TELEPORT_SPEED`, or one longer than
`StatedWalk.PLACEMENT_DISTANCE` (2.5 m) over a frame of any length. The
character controller starts a placed character at rest, with no footing to
jump from until it stands again.
- `StatedWalk.read(body, hasOwnMover) -> (walkX, walkZ, askedX, askedZ)?`: this
frame's stated walk across the frame `body` stands in. A body with a mover
of its own (a MovementState or a CharacterController on its entity) reads
its entity's statement; one with none reads the nearest ancestor's. Nil
when nothing states a walk for it.
- `StatedWalk.facing(vx, vz, askedX, askedZ, moveDeadzone) -> (dirX, dirZ)?`:
the direction a body turns toward: the walk asked for at any speed, else the
velocity once it is faster than `moveDeadzone`. Nil when the body keeps its
facing.
- `StatedWalk.moversChanged(body)`: tells the `Locomotion` and `LocomotionFull`
on `body` that a MovementState or a CharacterController came to its entity
or went from it, so each reads its movers again.
# stepSmoothing
> 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.
How a character's drawn body climbs a step its capsule takes at once. A
grounded character walking up or down a stair is put on the next tread in the
frame it reaches it: its capsule, and so its entity, rises or drops a whole
riser in one frame, and keeps that exact height. The character's direct
children that hold no collider and no physics body, with none below them
(its body mesh, a name label) are drawn shifted along its up by an offset that takes the riser back
and closes to zero as a critically damped spring, so the body is seen to climb
smoothly while the walls, the ground and every query see the character where
it stands.
A rise or drop the ground's slope accounts for (a ramp, a hill) is the walk
itself and is drawn as the capsule moves; only what goes past it (a riser, a
curb, a step down) is smoothed. The offset is held within the character's
step height, and a character placed by something else (a teleport, a respawn)
is drawn where it was placed at once.
The `CharacterController` component and the character module's `update` both
climb through here, so every character smooths its steps by one rule. The
component's `stepSmoothing` field and the module config's `stepSmoothing` are
the spring's smoothing time in seconds (default `0.1`); `0` draws the body on
the capsule every frame.
## Exports
- `StepSmoothing.new() -> Smoothing`: a fresh record for one character, no
offset and no child shifted, owned by the controller that moves it.
- `StepSmoothing.climbed(state, rise, travel, slopeAngle, stepHeight) -> offset`:
takes in one grounded step's rise along up. The part of `rise` past what a
slope of `slopeAngle` degrees gives `travel` metres across the ground puts
the drawn body back by that much, held within `stepHeight`.
- `StepSmoothing.settle(state, entityId, smoothTime, dt) -> offset`: closes the
offset by `dt` seconds of the spring and draws the entity's drawn children
at it. Costs nothing on a frame with no offset and no child shifted. The
record keeps its read of the entity's children and updates each child's
record in place, so a frame it closes allocates nothing while the scene's
structure stands; the first frame it closes after the structure changes (an
entity anywhere spawned, despawned, reparented, renamed or turned on or
off) reads the children again.
- `StepSmoothing.clear(state, entityId)`: draws the children back on the
capsule at once, for a character placed by something else, no longer moved
by its controller, or going away.
- `StepSmoothing.offset(state) -> number`: the offset along up in metres,
negative while the body is drawn below the capsule (after a step up).
- `StepSmoothing.active(state) -> boolean`: whether the body is drawn off the
capsule now; a controller keeps stepping a character while it is.
## Usage
```luau
local StepSmoothing = require("characterController.characterController.movement.stepSmoothing")
local smoothing = StepSmoothing.new()
-- In each grounded step that ended on the ground:
StepSmoothing.climbed(smoothing, dy, math.sqrt(dx * dx + dz * dz), slopeAngle, stepHeight)
-- Once a frame, after the steps:
StepSmoothing.settle(smoothing, entityId, 0.1, dt)
```
# velocity
> 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.
Velocity integration and per-frame movement resolution for the
character controller. Owns no state — every call takes the current
position / velocity / config / state and returns the new position
delta plus the updated velocity. Internally uses the `Ground`,
`Walls`, and `Ceiling` raycasting helpers.
## Exports
- `M.resolve(pos: Vec3, vel: Vec3, moveInput: MoveInput, config: Config, state, dt: number, selfId: string) -> (dx, dy, dz, vx, vy, vz, groundHit, wallHit, ceilHit)` —
apply gravity + air control, resolve wall slide / corner pin / the
steps a grounded body climbs (`Walls.move` with `stepHeight`) /
ceiling bonk / ground snap on the ground the footprint stands on
(`Ground.support`) / slope projection / steep-slope slide, in that
order.
Types:
- `Vec3 = { x: number, y: number, z: number }`
- `MoveInput = { x: number, z: number }` — world-space horizontal input.
- `Config = { height?, radius?, maxSlopeAngle?, stepHeight?, gravity?, airControlFactor?, groundSnapDistance?, skinWidth?, acceleration?, braking?, fallGravityMultiplier?, maxFallSpeed? }`
## Usage
```luau
local Velocity = require("characterController.characterController.movement.velocity")
local dx, dy, dz, vx, vy, vz, groundHit, wallHit, ceilHit =
Velocity.resolve(pos, vel, moveInput, config, state, dt, selfId)
```
## Notes
- The function is pure: it returns nine values but mutates nothing.
The caller is responsible for writing the position delta back via
`entity.localPosition.set` and updating its velocity field.
- Air control blends horizontal velocity toward the walk the input asks
for, at its full speed, with `airLerp = min(1, airControlFactor * 10 * dt)`:
a run held through a jump keeps its speed, and a turn or a change of speed
takes effect over `1 / (airControlFactor * 10)` seconds or so (at a factor
of 6 or more, within one 60 Hz frame). The blend is relative to
`state.keptMotion` (the motion kept from a moving body the character left)
when the state carries one, so the body goes on moving with it
(`Platform.steer`). Grounded mode uses direct assignment for responsive
feel.
- Ground cast distance is the larger of `groundSnapDistance` and
`stepHeight` plus two `skinWidth`s when grounded (the feet stand a skin
above the ground, and a second skin holds a riser of exactly
`stepHeight` in reach), so a body walks down stairs on its feet, and
`100` when airborne (so a fast fall doesn't tunnel past the floor).
Snap commit threshold is tight (the frame's own vertical travel),
so airborne ground hits don't snap unless they are within that
travel window.
- A grounded frame looks for ground above the feet as well, by the
rise its own travel covers on ground of `maxSlopeAngle` — that is
the ground a walking character climbs into. The seat takes it up to
the rise the surface it found covers over that travel, plus a step;
a surface further up stands across the path, and the character keeps
the ground it already has.
- Steep-slope (above `maxSlopeAngle`) hits set `groundHit._sliding =
true` so the state machine treats the frame as `sliding` rather
than `grounded`.
- A frame whose horizontal movement the wall pass cancels outright —
pressed straight into a wall, or wedged where two surfaces meet —
sets `wallHit._blocked = true`, so a refused walk reads as refused
instead of as a walk that happened to cover no ground.
- Step climbing only fires when `state.grounded`: the wall pass lifts the
body over a riser no taller than `stepHeight` that cut its walk short.
- On the ground the walk moves toward the input at `acceleration` and
`braking` (`Feel.walk` of `movement.feel`); along up the step is
`Feel.vertical`, which rises a jump `state._rise` holds against its own
gravity and scales and caps the fall. Missing settings read as
`Feel.DEFAULTS`.
# ceiling
> 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.
Single-ray ceiling-detection helper for the character controller.
Casts upward from the character's head to detect overhead obstacles
(head bonk, low clearance). No state.
## Exports
- `M.cast(x: number, y: number, z: number, height: number, skinWidth: number, selfId: string) -> hit?` —
cast a ray from `(x, y + height - skinWidth, z)` upward for
`skinWidth * 2`. Returns the raycast hit table or `nil`. The ray passes
through the colliders the body carries (`selfId` and every entity
parented under it), so a prop held overhead is never a ceiling.
## Usage
```luau
local Ceiling = require("characterController.characterController.physics.ceiling")
local hit = Ceiling.cast(px, py, pz, 1.8, 0.01, selfId)
if hit then
-- head bonk: zero out upward velocity
end
```
## Notes
- Pure function — no module state, no side effects beyond the engine
raycast itself.
- The ray is intentionally short (`skinWidth * 2`) so a head-bonk
check only fires when the character is actively pressing up
against a ceiling, not when there is ambient overhead geometry
far above.
# platform
> 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 body a character stands on, and how that body moves the character. A
character standing on a body that moves or turns (a lift, a moving platform,
a turntable, a raft, a ship's deck) is carried with it: the point under its
feet goes where the body takes it, and it turns with the body's turn about
up. Kinematic bodies a script moves, dynamic bodies the simulation moves and
transforms something animates carry it alike. In a multiplayer session a
character states its pose relative to the moving body it rides (`stateFrame`),
so every peer draws it on that body where that peer draws the body.
Poses are read where the frame draws them (`Physics.drawnPose`), so a
character carried by them stays in step with the platform on screen at any
frame rate and physics tick rate. A ride keeps how fast its body moved the
feet on each frame of its last tenth of a second, and of at least its last
six frames (`trail`): averaged, that is
how fast a kinematic body or an animated transform was carrying the character
when it leaves.
## Exports
- `M.pose(entityId) -> (x, y, z, rotation)?` — where an entity is drawn this
frame and how it is turned, in world space.
- `M.hold(entityId, from?, carry?, dt?) -> Ride?` — the body a character
stands on with the pose it is drawn at now. Hold it after the character is
placed each frame; passing the ride the frame began on (`from`), its
`carry` and the frame's `dt` keeps the ride's trail going on the same body.
- `M.carry(ride, x, y, z, up, dt?) -> Carry?` — how that body moved the point
`(x, y, z)` since the ride was held, and how fast it moves it this frame:
`{ entityId, dx, dy, dz, turn, moved, vx, vy, vz }`, `turn` the body's turn
about `up` as a quaternion, `v` the simulation's velocity for the body at the
point (linear plus spin), or the displacement over `dt` for an entity under
no body. nil with no ride or when its body is gone.
- `M.velocityAt(ride, carry, dt) -> (vx, vy, vz)` — how fast the body moves
the feet: a dynamic body's velocity there this frame, else the velocity
averaged over the ride's trail, this frame's `carry` included. What a character keeps as momentum when it leaves the body.
- `M.steer(vx, vz, walkX, walkZ, lerp, keptX, keptZ) -> (vx, vz)` — air
control for a character carrying the motion it kept from a body it left: the
velocity steers toward that motion plus the walk asked for, so with no walk
asked it goes on moving with the body it left.
- `M.keptPast(keptX, keptZ, vx, vz) -> (keptX, keptZ)` — the part of a kept
motion a wall leaves once it cut the step to the velocity `(vx, vz)`: none
for a wall met head on, the part along a wall slid along.
- `M.drawnRise(hit, up) -> number` — how far along `up` the surface a cast met
stands drawn above the point the cast met it at; `Ground.cast` measures the
ground's distance to the drawn surface with it.
- `M.turned(turn, r) -> Quat` — the rotation `r` turned by `turn` in world
space.
- `M.frameOf(entityId?) -> string?` — the entity a character standing on
`entityId` states its pose relative to for the other peers of a
multiplayer session: the entity of the body `entityId` belongs to when that
body is kinematic or dynamic, nil otherwise.
- `M.stateFrame(entityId, frame?, stated?) -> string?` — state the
character's pose relative to `frame` (`multiplayer.setPoseFrame`), or in
the world with nil, when it differs from `stated`; returns the frame stated
now. Every other peer then draws the character where it draws the body it
rides, in step with it.
## Usage
```luau
local Platform = require("characterController.characterController.physics.platform")
-- each frame, before moving the character
local carry = Platform.carry(ride, px, py, pz, up, dt)
if carry then px, py, pz = px + carry.dx, py + carry.dy, pz + carry.dz end
-- ... walk, cast for ground, place the character ...
ride = if grounded then Platform.hold(groundHit.entityId, ride, carry, dt) else nil
-- the frame the other peers of a session draw the character in
stated = Platform.stateFrame(entityId, Platform.frameOf(ride and ride.entityId), stated)
```
# walls
> 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.
Wall-detection and slide helpers for the character controller. Runs the
horizontal pass of a character's step, sweeps the character's own
capsule along the movement direction, puts a body that overlaps a wall
back outside it, probes a single height with a horizontal ray, and
slides a movement vector along a wall normal. No state.
## Exports
- `M.move(x: number, y: number, z: number, dx: number, dz: number, height: number, radius: number, skinWidth: number, maxSlopeAngle: number, selfId: string, frame: Frame?, cameFrom: Point?, stepHeight: number?) -> Step`:
the horizontal pass of one step. Puts a body that overlaps a wall back
outside it (`pushOut`), then carries it along `(dx, dz)`: the body stops
`skinWidth` short of the first wall the step runs into, and the rest of
the step slides along that wall and along the next one the slide meets.
With a `stepHeight`, a wall that cuts the walk short is walked again with
the body lifted by up to that much (as far as `headroom` allows); the
lifted walk is taken when it carries the body further and comes down on
walkable ground above the feet, no higher than a step, clear of every
wall, and the rest of the walk goes on from that step. Returns
`{ dx, dz, pushX, pushZ, overlapped, blocked, hit, stepUp }`: where the
body goes (push included), the push itself, whether the body overlapped a
wall where the step began, whether the step met a wall and gained no
ground towards where it asked to go, the first wall it met, and how far
above the feet the ground it stepped up onto stands.
- `M.headroom(x: number, y: number, z: number, sx: number, sz: number, maxRise: number, height: number, radius: number, skinWidth: number, maxSlopeAngle: number, selfId: string, frame: Frame?) -> number`:
how far the body at the feet `(x, y, z)` moved `(sx, sz)` across the
frame can rise, up to `maxRise`, before its head meets something
overhead.
- `M.pushOut(x: number, y: number, z: number, height: number, radius: number, skinWidth: number, maxSlopeAngle: number, selfId: string, frame: Frame?, cameFrom: Point?) -> (number, number, boolean)`:
the horizontal push that puts a body overlapping a wall back outside it,
`skinWidth` clear of the surface, and whether it overlapped one. The push
runs along the overlap's shortest way out, or back to the side
`cameFrom` stands on when the body's centre has crossed the surface since
it last stood there. `0, 0, false` for a body that overlaps no wall.
- `M.standsAt(placed: Point?, x: number, y: number, z: number) -> boolean`:
whether feet at `(x, y, z)` stand at `placed`, where a mover last put
them, to the precision a position is stored at (a 32-bit float's, which
coarsens with the distance from the origin). A mover keeps its
`cameFrom` only while this holds.
- `M.castBody(x: number, y: number, z: number, dirX: number, dirZ: number, height: number, radius: number, skinWidth: number, maxSlopeAngle: number, selfId: string, distance: number?) -> hit?`:
sweep the capsule spanning the character from the top of the ground
band above `(x, y, z)` (its feet) up to `y + height`, reaching
`distance + skinWidth` past its own surface (`skinWidth` alone when
`distance` is omitted). Returns the wall standing across the path, or
`nil` when the path is clear.
- `M.castDirection(x: number, y: number, z: number, dirX: number, dirZ: number, radius: number, skinWidth: number, selfId: string) -> hit?` —
single horizontal ray of length `radius + skinWidth`, from whichever
sample height the caller passes. The ray passes through the colliders
the body carries (`selfId` and every entity parented under it).
- `M.slideAlongWall(moveX: number, moveZ: number, normalX: number, normalZ: number) -> (number, number)` —
strip the component of `move` going into the wall (`v - (v . n) * n`,
XZ only). Returns input unchanged when `dot >= 0` or the XZ-normal
is effectively zero.
## Usage
```luau
local Walls = require("characterController.characterController.physics.walls")
local step = Walls.move(px, py, pz, vx * dt, vz * dt, 1.8, 0.3, 0.01, 45, selfId)
px, pz = px + step.dx, pz + step.dz
local hit = Walls.castBody(px, py, pz, dirX, dirZ, 1.8, 0.3, 0.01, 45, selfId)
if hit then
local slideX, slideZ = Walls.slideAlongWall(dx, dz, hit.normal.x, hit.normal.z)
end
```
## Notes
- `move` sweeps the whole step, so however long a frame's step is, the
body ends outside every wall it walks at, and the next step it asks for
starts clear of them, away from a wall it rests against as much as
along it.
- A sweep begun inside a wall answers about the overlap in whichever
direction it points. `pushOut` measures how deep the overlap goes by
sweeping the same body back in from one body width outside the wall, so
a body placed inside a wall, or shoved into one, walks again on the next
step. Each push reaches at most that body width, the deepest a body
reaches into a surface: a body overlapping one face of a hollow mesh
collider is put back outside that face, never across the collider at the
face on its far side. A start that lands on another surface of the same
collider, the far wall of a passage one mesh bounds on both sides, comes
in by half until it stands clear, so a body overlapping one wall of a
narrow passage is put back into the passage. A body deeper inside a
solid than its own width comes out a body width at a time.
- A surface has a way out on each side. The shortest is the side the
body's centre stands on, which is the far side once a long step has
carried the centre across a thin surface. A mover passes `cameFrom`,
the feet position of its last step that began with `overlapped` false,
and a body that last stood clear more than a radius behind the shortest
way out is pushed back out the side it came from. The CharacterController
keeps it while the body stands where the controller put it (`standsAt`),
and forgets it once anything else moves the body.
- A collider the body carries, on `selfId` or on an entity parented under
it (a held prop, a trigger volume that travels with the character), is
no wall: `castBody` sweeps through it and `pushOut` pushes nothing out
of it, so a character carrying one stands where it is put and walks.
- Another character is a wall: every entity carrying a
`CharacterController` stands as its upright capsule (`physics.characters`),
so `castBody` and `move` stop a skin short of it and slide around it, and a
hit on one carries `character = true`. `pushOut` pushes nothing out of
another character; a character moves itself apart from one it overlaps
(`Characters.apart`). Two characters the contact filter lets pass, by
their `contactTag`s, are no walls to each other.
- `castBody` sweeps the whole body, so an opening narrower than
`2 * radius` stops the character even when nothing stands on the
centre line — two cabinets 6 cm apart are a wall, not a doorway.
- A contact whose surface faces up or down — the ramps the character
walks up, to `maxSlopeAngle`, and anything directly overhead —
belongs to the ground and ceiling passes. `castBody` runs on up along
a ramp it meets, the way the body climbs it, so a body on a ramp still
reports the wall ahead of it, whether that wall is part of the ramp's
collider or another; it sweeps on past a surface overhead.
- A contact on the rim of a surface (the edge of a stair or a curb), where
the surface under the contact faces another way than the contact does,
stands across the path the way a wall does: `move`'s step pass decides
whether the body climbs it.
- `castBody` starts its sweep above the ground band: a cap of `radius`
resting on ground of angle `a` reaches `radius * (1 / cos(a) - 1)`
below the surface uphill of it, and a sweep begun inside a surface
describes the shortest way out of that overlap instead of the surface
standing across the path. The band is measured at `maxSlopeAngle`, the
steepest ground the character walks, and the ground and step passes own
everything under it.
- `slideAlongWall` normalises the wall normal in XZ; callers don't
need to pre-normalise. The Y component of the normal is ignored
because slide-along is a horizontal operation.
- The slide helper returns the input movement unchanged whenever the
movement isn't pressing into the wall — there's no "stick to wall"
behaviour, only "don't pass through".
# ground
> 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.
Ground-probing and slope-math helpers for the character controller.
A downward raycast helper plus two pure vector helpers (slope angle,
plane projection). No state.
## Exports
- `M.cast(x: number, y: number, z: number, skinWidth: number, maxDist: number, selfId: string, riseDist: number?) -> hit?` —
cast a ray downward from `(x, y + riseDist + skinWidth, z)`, reaching
`maxDist` below the feet. The returned hit's `distance` is adjusted to
be relative to the feet, not the ray origin, and is negative for
ground standing above them. The ray passes through the colliders the
body carries (`selfId` and every entity parented under it), so a prop
held at the feet is never the ground.
- `M.support(x: number, y: number, z: number, radius: number, skinWidth: number, maxDist: number, selfId: string, riseDist: number?, maxSlopeAngle: number?, frame: Frame?) -> hit?` —
the ground the body's footprint stands on: the surface under its centre
(`cast`), or a walkable surface under the rest of the disc of `radius`
around the centre where that stands higher than the centre's ground
continued out to it. A body whose front has stepped over the edge of a
stair stands on that stair, and one walking off a ledge stands on the
ledge until the last of its footprint leaves it. A hit from under the
footprint carries `edge = true` and the surface's own normal.
- `M.slopeAngle(nx: number, ny: number, nz: number) -> number` —
degrees between the supplied normal and world up. Returns 0 on a
zero-length normal.
- `M.projectOnSlope(moveX, moveY, moveZ, normalX, normalY, normalZ) -> (number, number, number)` —
project a movement vector onto the plane perpendicular to a normal:
`v - (v . n) * n`.
## Usage
```luau
local Ground = require("characterController.characterController.physics.ground")
local hit = Ground.cast(px, py, pz, 0.01, 0.2, selfId)
if hit then
local angle = Ground.slopeAngle(hit.normal.x, hit.normal.y, hit.normal.z)
if angle <= 45 then
-- walkable
end
end
local px, py, pz = Ground.projectOnSlope(dx, 0, dz, nx, ny, nz)
```
## Notes
- `cast` shifts the origin up by `skinWidth` to avoid starting the ray
inside the ground when the character is sitting on a contact, then
subtracts `skinWidth` back off `hit.distance` so callers see the
true distance from the feet.
- `riseDist` raises the origin further, so the ray also covers ground
that stands above the feet — the ground a walking character climbs
into. A hit up there reports a negative `distance`: how far the
character rises to stand on it.
- `slopeAngle` clamps `cos(angle)` into `[-1, 1]` before `acos` —
callers don't need to normalise the input.
- `projectOnSlope` does not normalise the surface normal; callers
should pass a unit normal (raycast normals already are).