Camera systems
The camera is the player's window; bad camera work makes a good game feel awful. This skill
covers the engine-neutral camera techniques — smooth follow, deadzones, look-ahead, bounds
clamping, third-person orbit with collision, first-person look, and multi-target framing — and
maps them onto each engine's camera node or rig.
When to use
- Use when a 2D camera should follow the player smoothly, stay inside the level, lead the
player's motion, or ignore small movements (deadzone).
- Use when building a 3D third-person orbit camera (mouse/stick look, collision push-in) or a
first-person look controller, or framing multiple targets at once.
- Use to fix camera jitter, snapping, motion sickness, or a camera that shows past the level edge.
When not to use: for the magnitude and trigger of screen shake and impact juice, use
game-feel (this skill exposes the shake offset hook it drives). For the engine's concrete
camera node/component setup, use godot-3d-essentials (Camera3D, environment) or the engine
skill. For player movement itself use the engine movement skill (godot-2d-movement). For
performance of many cameras/render targets, see performance-optimization.
Core workflow
- Decide what the camera serves. Platformer (lead the jump, see hazards), top-down (center
with deadzone), third-person (orbit + collision), first-person (look only). The genre sets the
rules.
- Follow smoothly and frame-rate independently. Move the camera toward the target with
exponential smoothing or a spring (
SmoothDamp), not a fixed lerp(a, b, 0.1) — that 0.1 is
per-frame and changes with frame rate.
- Add a deadzone so tiny target movements don't nudge the camera; it only follows once the
target leaves a box/zone. Stops nausea in twitchy games.
- Lead the action with look-ahead by offsetting the camera target in the direction of
motion or facing, eased in/out so it doesn't whip.
- Clamp to level bounds so the camera never shows outside the playable area; combine with
smoothing so it eases to a stop at the edge.
- For 3D, separate look from collision. Orbit via yaw/pitch on a rig; use a spring arm /
ray to pull the camera in when geometry blocks it; clamp pitch.
- Update the camera after the target moves. Follow in the late/post step (after movement and
physics resolve) to avoid a one-frame lag jitter.
- Verify by moving the target at low and high frame rates, into corners and walls, and at
the level edges; confirm no jitter, no peeking past bounds, smooth stops. Report what you saw.
Patterns
1. Godot 2D built-in follow: smoothing + bounds (don't hand-roll first)
# Godot 4.7 Camera2D. Engine-provided smoothing + hard limits + drag margins.
@onready var cam := $Camera2D
func _ready() -> void:
cam.make_current()
cam.position_smoothing_enabled = true
cam.position_smoothing_speed = 6.0 # higher = snappier; lower = floatier
cam.limit_left = 0; cam.limit_top = 0 # clamp to the level rect (pixels)
cam.limit_right = level_width; cam.limit_bottom = level_height
cam.drag_horizontal_enabled = true # built-in deadzone via drag margins
2. Frame-rate-independent smooth follow (when you hand-roll it)
# RIGHT: exponential smoothing — same feel at any FPS. `rate` ~ 5..12.
func _follow(dt: float) -> void:
var t := 1.0 - exp(-rate * dt) # converges correctly regardless of dt
global_position = global_position.lerp(target.global_position, t)
# WRONG: global_position = global_position.lerp(target.global_position, 0.1)
# → faster smoothing at higher FPS; different feel on every machine.
# Unity 6.3 LTS: Vector3.SmoothDamp(transform.position, target.position, ref vel, smoothTime) in
# LateUpdate gives the same spring behavior with built-in frame-rate correction.
3. Deadzone + look-ahead (lead the player, ignore jitter)
# Camera only chases once the target leaves the deadzone box, then aims AHEAD of motion.
func _camera_target(dt: float) -> Vector2:
var to := target.global_position - _focus
var dz := deadzone_half_extents # e.g. Vector2(48, 32)
# Only move the focus by the overflow beyond the deadzone (per axis).
_focus.x += clampf(absf(to.x) - dz.x, 0, INF) * signf(to.x)
_focus.y += clampf(absf(to.y) - dz.y, 0, INF) * signf(to.y)
var lead := target.velocity.normalized() * look_ahead_dist # aim ahead of travel
return _focus + lead
4. 3D third-person orbit with collision push-in
# Godot 4.7. Yaw/pitch a pivot; a SpringArm3D auto-pulls the camera in when blocked.
func _unhandled_input(e):
if e is InputEventMouseMotion and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
# screen_relative is unscaled; `relative` is scaled by the stretch settings, so
# sensitivity would change with window size. The docs recommend screen_relative
# for captured-mouse aiming.
_yaw -= e.screen_relative.x * sensitivity
_pitch = clampf(_pitch - e.screen_relative.y * sensitivity,
deg_to_rad(-80.0), deg_to_rad(45.0)) # clamp pitch!
func _process(_dt):
pivot.rotation = Vector3(_pitch, _yaw, 0)
# $SpringArm3D handles wall collision: set spring_length + collision_mask; the child
# Camera3D slides in automatically. RIGHT: spring arm. WRONG: camera clips through walls.
# Unity 6.3 LTS: a Cinemachine 3 CinemachineCamera (namespace Unity.Cinemachine) with an Orbital
# Follow + Cinemachine Deoccluder; the CinemachineBrain on the Camera blends automatically.
5. Screen shake hook (owned trigger lives in game-feel)
# Expose an additive offset the game-feel trauma model writes to; follow + shake compose.
var shake_offset := Vector2.ZERO # set each frame by game-feel (trauma^2 * noise)
func _apply(final_focus: Vector2) -> void:
global_position = final_focus + shake_offset # shake rides ON TOP of smooth follow
# Unity Cinemachine 3: CinemachineBasicMultiChannelPerlin (AmplitudeGain/FrequencyGain) for
# continuous noise driven by trauma; for one-off impacts, a CinemachineImpulseSource on the
# hitter plus a CinemachineImpulseListener on the camera.
Pitfalls
lerp(pos, target, const) per frame is frame-rate dependent — floatier at 30 FPS, snappier
at 144. Use 1 - exp(-rate*dt) or SmoothDamp.
- Following in the normal update before the target has moved yields a one-frame lag jitter.
Follow in
LateUpdate / after movement/physics resolve.
- No bounds clamp lets the camera show black past the level edge. Clamp focus to the level
rect (account for the viewport half-size so the view, not the center, stays inside).
- No deadzone in twitchy games makes the camera twitch with every micro-movement → nausea.
- Unclamped pitch in third/first-person flips the camera over the top. Clamp pitch (about
-80° to +45° for an orbit, ±80° for first-person).
- Mouse-look sensitivity that changes with window size (Godot):
InputEventMouseMotion.relative
is scaled by the stretch settings; read screen_relative for captured-mouse aiming.
- Camera clipping through walls in 3D — use a spring arm / occlusion ray to pull in.
- Snapping on teleport/respawn is jarring; either hard-cut intentionally (and reset
smoothing) or fast-ease. Don't let a huge
SmoothDamp distance whip across the level.
- Shake driving the follow target instead of an additive offset makes follow fight shake.
Compose: smooth follow first, add shake offset last.
- Per-axis vs radial deadzone confusion — a box deadzone feels different from a circular one;
pick deliberately.
References
- For the exponential-smoothing/spring derivation, a complete deadzone+look-ahead+bounds 2D rig,
3D spring-arm/orbit details, first-person look, multi-target/group framing and split-screen,
cinematic camera blends, and the Cinemachine 3 / Godot Camera2D / PhantomCamera mapping, read
references/follow-and-framing.md.
Related skills
game-feel — owns screen-shake trauma/triggers; this skill exposes the offset it writes.
godot-2d-movement, godot-3d-essentials — the player/world the camera frames; Camera3D setup.
physics-tuning — interpolate camera follow with the physics step to kill jitter.
platformer, fps-shooter — genres whose camera rules this skill implements.
performance-optimization — cost of extra cameras, render targets, and split-screen.
1---2name: camera-systems3description: >4 Build game cameras that feel good — 2D follow with a deadzone, look-ahead, smoothing, and5 level-bounds clamping; 3D third-person orbit with collision and first-person look; plus6 multi-target framing and a shake hook. Engine-neutral techniques that pair with the engine's7 camera node and rigs like Unity Cinemachine or Godot Camera2D/PhantomCamera. Use when the user8 mentions camera follow, follow camera, deadzone, look-ahead, camera smoothing, camera bounds/9 limits, third-person camera, orbit camera, first-person look, Cinemachine, or camera jitter.10metadata:11 source: https://skillmd.com/skills/junmystery/camera-systems12---1314# Camera systems1516The camera is the player's window; bad camera work makes a good game feel awful. This skill17covers the engine-neutral camera techniques — smooth follow, deadzones, look-ahead, bounds18clamping, third-person orbit with collision, first-person look, and multi-target framing — and19maps them onto each engine's camera node or rig.2021## When to use2223- Use when a 2D camera should follow the player smoothly, stay inside the level, lead the24 player's motion, or ignore small movements (deadzone).25- Use when building a 3D third-person orbit camera (mouse/stick look, collision push-in) or a26 first-person look controller, or framing multiple targets at once.27- Use to fix camera jitter, snapping, motion sickness, or a camera that shows past the level edge.2829**When *not* to use:** for the *magnitude and trigger* of screen shake and impact juice, use30`game-feel` (this skill exposes the shake offset hook it drives). For the engine's concrete31camera node/component setup, use `godot-3d-essentials` (Camera3D, environment) or the engine32skill. For player movement itself use the engine movement skill (`godot-2d-movement`). For33performance of many cameras/render targets, see `performance-optimization`.3435## Core workflow36371. **Decide what the camera serves.** Platformer (lead the jump, see hazards), top-down (center38 with deadzone), third-person (orbit + collision), first-person (look only). The genre sets the39 rules.402. **Follow smoothly and frame-rate independently.** Move the camera toward the target with41 exponential smoothing or a spring (`SmoothDamp`), not a fixed `lerp(a, b, 0.1)` — that 0.1 is42 per-frame and changes with frame rate.433. **Add a deadzone** so tiny target movements don't nudge the camera; it only follows once the44 target leaves a box/zone. Stops nausea in twitchy games.454. **Lead the action with look-ahead** by offsetting the camera target in the direction of46 motion or facing, eased in/out so it doesn't whip.475. **Clamp to level bounds** so the camera never shows outside the playable area; combine with48 smoothing so it eases to a stop at the edge.496. **For 3D, separate look from collision.** Orbit via yaw/pitch on a rig; use a spring arm /50 ray to pull the camera in when geometry blocks it; clamp pitch.517. **Update the camera after the target moves.** Follow in the late/post step (after movement and52 physics resolve) to avoid a one-frame lag jitter.538. **Verify by moving the target at low and high frame rates**, into corners and walls, and at54 the level edges; confirm no jitter, no peeking past bounds, smooth stops. Report what you saw.5556## Patterns5758### 1. Godot 2D built-in follow: smoothing + bounds (don't hand-roll first)5960```gdscript61# Godot 4.7 Camera2D. Engine-provided smoothing + hard limits + drag margins.62@onready var cam := $Camera2D63func _ready() -> void:64 cam.make_current()65 cam.position_smoothing_enabled = true66 cam.position_smoothing_speed = 6.0 # higher = snappier; lower = floatier67 cam.limit_left = 0; cam.limit_top = 0 # clamp to the level rect (pixels)68 cam.limit_right = level_width; cam.limit_bottom = level_height69 cam.drag_horizontal_enabled = true # built-in deadzone via drag margins70```7172### 2. Frame-rate-independent smooth follow (when you hand-roll it)7374```gdscript75# RIGHT: exponential smoothing — same feel at any FPS. `rate` ~ 5..12.76func _follow(dt: float) -> void:77 var t := 1.0 - exp(-rate * dt) # converges correctly regardless of dt78 global_position = global_position.lerp(target.global_position, t)79# WRONG: global_position = global_position.lerp(target.global_position, 0.1)80# → faster smoothing at higher FPS; different feel on every machine.81# Unity 6.3 LTS: Vector3.SmoothDamp(transform.position, target.position, ref vel, smoothTime) in82# LateUpdate gives the same spring behavior with built-in frame-rate correction.83```8485### 3. Deadzone + look-ahead (lead the player, ignore jitter)8687```gdscript88# Camera only chases once the target leaves the deadzone box, then aims AHEAD of motion.89func _camera_target(dt: float) -> Vector2:90 var to := target.global_position - _focus91 var dz := deadzone_half_extents # e.g. Vector2(48, 32)92 # Only move the focus by the overflow beyond the deadzone (per axis).93 _focus.x += clampf(absf(to.x) - dz.x, 0, INF) * signf(to.x)94 _focus.y += clampf(absf(to.y) - dz.y, 0, INF) * signf(to.y)95 var lead := target.velocity.normalized() * look_ahead_dist # aim ahead of travel96 return _focus + lead97```9899### 4. 3D third-person orbit with collision push-in100101```gdscript102# Godot 4.7. Yaw/pitch a pivot; a SpringArm3D auto-pulls the camera in when blocked.103func _unhandled_input(e):104 if e is InputEventMouseMotion and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:105 # screen_relative is unscaled; `relative` is scaled by the stretch settings, so106 # sensitivity would change with window size. The docs recommend screen_relative107 # for captured-mouse aiming.108 _yaw -= e.screen_relative.x * sensitivity109 _pitch = clampf(_pitch - e.screen_relative.y * sensitivity,110 deg_to_rad(-80.0), deg_to_rad(45.0)) # clamp pitch!111func _process(_dt):112 pivot.rotation = Vector3(_pitch, _yaw, 0)113 # $SpringArm3D handles wall collision: set spring_length + collision_mask; the child114 # Camera3D slides in automatically. RIGHT: spring arm. WRONG: camera clips through walls.115# Unity 6.3 LTS: a Cinemachine 3 CinemachineCamera (namespace Unity.Cinemachine) with an Orbital116# Follow + Cinemachine Deoccluder; the CinemachineBrain on the Camera blends automatically.117```118119### 5. Screen shake hook (owned trigger lives in `game-feel`)120121```gdscript122# Expose an additive offset the game-feel trauma model writes to; follow + shake compose.123var shake_offset := Vector2.ZERO # set each frame by game-feel (trauma^2 * noise)124func _apply(final_focus: Vector2) -> void:125 global_position = final_focus + shake_offset # shake rides ON TOP of smooth follow126# Unity Cinemachine 3: CinemachineBasicMultiChannelPerlin (AmplitudeGain/FrequencyGain) for127# continuous noise driven by trauma; for one-off impacts, a CinemachineImpulseSource on the128# hitter plus a CinemachineImpulseListener on the camera.129```130131## Pitfalls132133- **`lerp(pos, target, const)` per frame** is frame-rate dependent — floatier at 30 FPS, snappier134 at 144. Use `1 - exp(-rate*dt)` or `SmoothDamp`.135- **Following in the normal update before the target has moved** yields a one-frame lag jitter.136 Follow in `LateUpdate` / after movement/physics resolve.137- **No bounds clamp** lets the camera show black past the level edge. Clamp focus to the level138 rect (account for the viewport half-size so the *view*, not the center, stays inside).139- **No deadzone in twitchy games** makes the camera twitch with every micro-movement → nausea.140- **Unclamped pitch** in third/first-person flips the camera over the top. Clamp pitch (about141 -80° to +45° for an orbit, ±80° for first-person).142- **Mouse-look sensitivity that changes with window size** (Godot): `InputEventMouseMotion.relative`143 is scaled by the stretch settings; read `screen_relative` for captured-mouse aiming.144- **Camera clipping through walls** in 3D — use a spring arm / occlusion ray to pull in.145- **Snapping on teleport/respawn** is jarring; either hard-cut intentionally (and reset146 smoothing) or fast-ease. Don't let a huge `SmoothDamp` distance whip across the level.147- **Shake driving the follow target** instead of an additive offset makes follow fight shake.148 Compose: smooth follow first, add shake offset last.149- **Per-axis vs radial deadzone confusion** — a box deadzone feels different from a circular one;150 pick deliberately.151152## References153154- For the exponential-smoothing/spring derivation, a complete deadzone+look-ahead+bounds 2D rig,155 3D spring-arm/orbit details, first-person look, multi-target/group framing and split-screen,156 cinematic camera blends, and the Cinemachine 3 / Godot Camera2D / PhantomCamera mapping, read157 `references/follow-and-framing.md`.158159## Related skills160161- `game-feel` — owns screen-shake trauma/triggers; this skill exposes the offset it writes.162- `godot-2d-movement`, `godot-3d-essentials` — the player/world the camera frames; Camera3D setup.163- `physics-tuning` — interpolate camera follow with the physics step to kill jitter.164- `platformer`, `fps-shooter` — genres whose camera rules this skill implements.165- `performance-optimization` — cost of extra cameras, render targets, and split-screen.