Builtin Library
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 look);rotationSmoothinghow quickly the aim swings to a new heading. - Collision pull-in. Each frame a sphere of
cameraRadiusis swept from the point the camera looks at out to the camera. When a collider is in the way the camera comes in to it on that frame, so no frame is drawn from inside a wall, and once the way is clear it eases back out overpullOutTime. 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. - 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.
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. |
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. |
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.