camera-systems
Builds and tunes game cameras, engine-neutral with Godot and Cinemachine 3 mappings: 2D follow with deadzone and look-ahead, third-person orbit, first-person look and split-screen. Use when the camera lags, jitters while following, shows past the level edge, clips through walls or changes with frame rate. Not for shake (`game-feel`) or physics timestep jitter (`physics-tuning`).
gamedev-skills · 已有静态检查记录
安装与使用
运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。
npx skills add gamedev-skills/awesome-gamedev-agent-skills --skill camera-systems技能说明
name: camera-systems
description: >
Builds and tunes game cameras, engine-neutral with Godot and Cinemachine 3 mappings: 2D follow
with deadzone and look-ahead, third-person orbit, first-person look and split-screen. Use when
the camera lags, jitters while following, shows past the level edge, clips through walls or
changes with frame rate. Not for shake (game-feel) or physics timestep jitter
(physics-tuning).
Camera systems
A good camera follows smoothly at any frame rate, leads the action, never shows outside the level and never clips through walls. This skill owns those techniques and maps them onto each engine's camera node or rig; prefer the engine's built-in rig before hand-rolling one.
When to use
- A 2D camera should follow smoothly, ignore small movements, lead motion and stay in bounds.
- A 3D third-person orbit or first-person look controller, or framing several targets.
- Fixing jitter, snapping, motion sickness or a camera that peeks past the level.
Not this skill: shake magnitude and triggers (game-feel; this skill only exposes the
offset), physics jitter of the body itself (physics-tuning), Camera3D and environment setup
(godot-3d-essentials), player movement (godot-2d-movement or the engine movement skill),
look-sensitivity input curves (input-systems).
Core workflow
- Decide what the camera serves. Platformer (lead the jump, see hazards), top-down (centre with deadzone), third-person (orbit plus collision), first-person (look only).
- Use the built-in rig first: Godot
Camera2Dsmoothing, limits and drag margins, orSpringArm3D; Unity Cinemachine 3 (CinemachineCameraplus Position Composer, Orbital Follow, Deoccluder, Confiner). Hand-roll only what the rig cannot do. - Smooth with
1 - exp(-rate * dt)or a critically damped spring (SmoothDamp), never a fixedlerp(a, b, 0.1)per frame. - Add a deadzone, then look-ahead eased toward its goal so direction flips don't whip.
- Clamp the view, not the centre, to the level rectangle, accounting for zoom.
- For 3D, separate look from collision: yaw and pitch on a pivot, a spring arm or ray pulls the camera in, pitch clamped.
- Update after the target moves (late update, or after physics) and follow the target's interpolated transform when physics interpolation is on.
- Verify with a runnable check, then by eye. Step the follow code headless with a target
moving at 300 px/s for 2 s at
dt = 1/30and atdt = 1/144, and compare how far the camera trails the target. Withrate = 8exponential smoothing the lag is about 33 px and 37 px; a fixedlerp(..., 0.1)gives about 90 px and 19 px, a sign the follow is frame-rate dependent. Then ask the user to run into corners, walls and level edges at low and high frame rates and report any jitter, peeking or snapping.
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.