Log inGet started
Package

chase.component

Newest version

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. positionSmoothing softens a change of the framing (the target turning, a zoom, a stick's or a finger's look, the swing back behind the target); a mouse look turns the camera on the frame the mouse moves. rotationSmoothing how quickly the aim swings to a new heading.
  • Collision pull-in. Each frame a sphere of cameraRadius is swept from height * 0.5 over the target itself (wherever the framed point lags) out to the camera. Sweeps of that line ahead bring the camera in ahead of what is about to come between it and the target, at the speed that has it clear when the line gets there, and something no sweep could see coming brings it in on the frame it blocks the view, so no frame is drawn from inside a wall; once the way is clear it eases back out over pullOutTime. With less than 0.4 m of room on the line, the camera turns round the target to the nearest turn that has it. The aim comes down from above the target toward it as the camera comes in, so a camera pulled in close still holds the target in the picture. Every collider stops the sweep, invisible ones included; cameraIgnore lists the ones the camera sees through.
  • Fading what fills the view. In play a thin occluder (a post, a lamp pole, a railing: a collider no wider than occluderFadeWidth across the line to the target at its narrowest, and no deeper along it) does not pull the camera in: while it stands between the camera and the target it fades to occluderFade, that share of its pixels left undrawn in a screen-space dither. The target fades as the camera comes within bodyFadeDistance of the point the sweep starts from, reaching bodyFade at the nearest the camera stands. Each fade eases over fadeTime; shadows stay whole and the fade is this engine's own. fadeIgnore lists entities never faded, occluderFade = 0 pulls in for every collider, and chase:fading() reports what fades.
  • Free-look. The look control orbits the camera around the target, up to lookYawLimit either side and between lookPitchMin and lookPitchMax, and the camera swings back behind the target lookReturnDelay seconds after the control is let go. chase:recenter() swings it back now, over lookReturnTime.
  • Bumps and landings are eased. The camera frames a point that follows the target's motion with lag: verticalLag (default 0.15 s) eases a bump, a ramp's lip or a landing, held to maxVerticalLag (0.5 m); horizontalLag (default 0, so the distance holds at any speed) and maxHorizontalLag do the same across the ground. leadTime (default 0), maxLead and leadSmoothing run the aim ahead along the target's motion, on top of lookAhead. chase:tracking() answers the lag, the lead and the target's velocity as the rig measures them.

Vs. orbital_follow

orbital_followchase
Orbitlook control (yaw + pitch), stays where it was leftfree-look that swings back behind the target
Headingthe rig's ownderived from the target's facing
Position easeper-axis time constantsper-second blend of the framing
Rotation easen/aseparate per-second blend
Best forcharacter action, RPGvehicles, platformers, ski/snowboard

Fields

FieldDefaultNotes
targetunsetThe 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.
distance6.0Horizontal trail distance behind target, at any speed.
height2.5Vertical offset above target origin.
minDistance, maxDistance1.5, 25.0Scroll-zoom bounds.
zoomSpeed0.12exp(-scroll * zoomSpeed) per tick.
positionSmoothing0.05Share of a framing change left after one second. 0 = locked, 1 = static. A mouse look lands on the frame it arrives.
rotationSmoothing0.15The same for the aim swinging to a new heading.
lookAhead0.6How far in front of target the camera aims.
cameraRadius0.3Radius of the pull-in sweep. 0 turns the pull-in off.
cameraIgnore{}Entities whose colliders the pull-in passes through.
pullOutTime0.4Seconds (time constant) of the ease back out once the way is clear.
occluderFade0.8Share 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.
occluderFadeWidth1.5Metres an occluder stands across the line to the target at its narrowest, and along it, at most, to fade.
bodyFade0.9Share of the target's pixels left undrawn with the camera at its nearest, in play. 0 keeps it whole.
bodyFadeDistance1.0Metres from the sweep's start within which the target fades.
fadeTime0.15Seconds a fade takes from none to full, or back.
fadeIgnore{}Entities the camera never fades.
lookSensitivity0.3Degrees per unit of the look control.
lookYawLimit180Degrees free-look orbits either side of behind.
lookPitchMin, lookPitchMax-60, 15Degrees free-look tilts down (raising the camera) and up (lowering it).
lookReturnDelay1.0Seconds after the look is let go before the camera swings back. Negative holds it.
lookReturnTime0.35Seconds (time constant) of the swing back.
invertYfalseForward on the look control looks up unless this is on.
inputMap@builtin::inputMaps.cameraRigThe 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 read Camera.follow, so a key that switches views writes the Camera's behavior.