chase.component
This package holds more than this page lists. See all of its files in its world.
README.md
Chase Camera
A follow cam that trails behind the target's facing at a fixed distance and height. Designed for vehicles and fast platformers where orbital_follow's orbit feels too floaty.
- The distance holds at any speed. The camera trails the target where it is drawn this frame, and what eases is its offset from the target, so a camera set 6 m behind a car stands 6 m behind it at 5 m/s and at 200 m/s.
positionSmoothingsoftens a change of the framing (the target turning, a zoom, a stick's or a finger's look, the swing back behind the target); a mouse look turns the camera on the frame the mouse moves.rotationSmoothinghow quickly the aim swings to a new heading. - Collision pull-in. Each frame a sphere of
cameraRadiusis swept fromheight * 0.5over the target itself (wherever the framed point lags) out to the camera. Sweeps of that line ahead bring the camera in ahead of what is about to come between it and the target, at the speed that has it clear when the line gets there, and something no sweep could see coming brings it in on the frame it blocks the view, so no frame is drawn from inside a wall; once the way is clear it eases back out overpullOutTime. With less than 0.4 m of room on the line, the camera turns round the target to the nearest turn that has it. The aim comes down from above the target toward it as the camera comes in, so a camera pulled in close still holds the target in the picture. Every collider stops the sweep, invisible ones included;cameraIgnorelists the ones the camera sees through. - Fading what fills the view. In play a thin occluder (a post, a lamp pole, a railing: a collider no wider than
occluderFadeWidthacross the line to the target at its narrowest, and no deeper along it) does not pull the camera in: while it stands between the camera and the target it fades tooccluderFade, that share of its pixels left undrawn in a screen-space dither. The target fades as the camera comes withinbodyFadeDistanceof the point the sweep starts from, reachingbodyFadeat the nearest the camera stands. Each fade eases overfadeTime; shadows stay whole and the fade is this engine's own.fadeIgnorelists entities never faded,occluderFade = 0pulls in for every collider, andchase:fading()reports what fades. - Free-look. The
lookcontrol orbits the camera around the target, up tolookYawLimiteither side and betweenlookPitchMinandlookPitchMax, and the camera swings back behind the targetlookReturnDelayseconds after the control is let go.chase:recenter()swings it back now, overlookReturnTime. - Bumps and landings are eased. The camera frames a point that follows the target's motion with lag:
verticalLag(default0.15s) eases a bump, a ramp's lip or a landing, held tomaxVerticalLag(0.5m);horizontalLag(default0, so the distance holds at any speed) andmaxHorizontalLagdo the same across the ground.leadTime(default0),maxLeadandleadSmoothingrun the aim ahead along the target's motion, on top oflookAhead.chase:tracking()answers the lag, the lead and the target's velocity as the rig measures them.
Vs. orbital_follow
orbital_follow | chase | |
|---|---|---|
| Orbit | look control (yaw + pitch), stays where it was left | free-look that swings back behind the target |
| Heading | the rig's own | derived from the target's facing |
| Position ease | per-axis time constants | per-second blend of the framing |
| Rotation ease | n/a | separate per-second blend |
| Best for | character action, RPG | vehicles, platformers, ski/snowboard |
Fields
| Field | Default | Notes |
|---|---|---|
target | unset | The entity to chase: the entity, its id or its name. An entity reference, so a scene build that writes it names the entity the build placed. Falls back to Camera.follow when unset. |
distance | 6.0 | Horizontal trail distance behind target, at any speed. |
height | 2.5 | Vertical offset above target origin. |
minDistance, maxDistance | 1.5, 25.0 | Scroll-zoom bounds. |
zoomSpeed | 0.12 | exp(-scroll * zoomSpeed) per tick. |
positionSmoothing | 0.05 | Share of a framing change left after one second. 0 = locked, 1 = static. A mouse look lands on the frame it arrives. |
rotationSmoothing | 0.15 | The same for the aim swinging to a new heading. |
lookAhead | 0.6 | How far in front of target the camera aims. |
cameraRadius | 0.3 | Radius of the pull-in sweep. 0 turns the pull-in off. |
cameraIgnore | {} | Entities whose colliders the pull-in passes through. |
pullOutTime | 0.4 | Seconds (time constant) of the ease back out once the way is clear. |
occluderFade | 0.8 | Share of a thin occluder's pixels left undrawn while it stands in the way, in play. 0 pulls in for it as for a wall. |
occluderFadeWidth | 1.5 | Metres an occluder stands across the line to the target at its narrowest, and along it, at most, to fade. |
bodyFade | 0.9 | Share of the target's pixels left undrawn with the camera at its nearest, in play. 0 keeps it whole. |
bodyFadeDistance | 1.0 | Metres from the sweep's start within which the target fades. |
fadeTime | 0.15 | Seconds a fade takes from none to full, or back. |
fadeIgnore | {} | Entities the camera never fades. |
lookSensitivity | 0.3 | Degrees per unit of the look control. |
lookYawLimit | 180 | Degrees free-look orbits either side of behind. |
lookPitchMin, lookPitchMax | -60, 15 | Degrees free-look tilts down (raising the camera) and up (lowering it). |
lookReturnDelay | 1.0 | Seconds after the look is let go before the camera swings back. Negative holds it. |
lookReturnTime | 0.35 | Seconds (time constant) of the swing back. |
invertY | false | Forward on the look control looks up unless this is on. |
inputMap | @builtin::inputMaps.cameraRig | The map look and zoom are read from. A write on a live rig takes up the new map. |
Use as a camera behavior
local camera = entity.find("cam").component.get("Camera")
camera.behavior = asset.ref("@builtin::controller.chase", "component")
camera.follow = car
The component carries the cameraBehavior tag in .metadata.
Controls
The camera-rig map (@builtin::inputMaps.cameraRig), whose group stays live while a vehicle's map holds the player's controls:
- Look: right-button drag, the right stick, or a drag on the right of a touch screen. Orbits the camera; it swings back behind the target when let go.
- Zoom: scroll wheel, shoulder buttons, pinch. Changes
distance.
For mouse look with no button held, point inputMap at a map of the world's own in the camera group that declares look and zoom with pointerLock = true: the camera group stays live while a vehicle holds the player's controls.
A vehicle that forwards its own zoom control to a chase camera (VehicleController.camera) leaves alone a camera that hears zoom from its own map, so one notch zooms once.
Pair with
VehicleController: the car turns, the chase camera trails its facing and holds its distance at any speed.standard_controller: the controller rotates the player to face the input direction; chase locks behind that facing.controller.mount: the same car seen from the driver's seat or the hood. Both readCamera.follow, so a key that switches views writes the Camera'sbehavior.