Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commit44fd9e59bd

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 look); rotationSmoothing how quickly the aim swings to a new heading.
  • Collision pull-in. Each frame a sphere of cameraRadius is 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 over pullOutTime. 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.
  • 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.

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.
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.
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.