/dm-game:camera-controlfrom dm-game
Controlling a 2D or top-down game camera, not juicing it: a pure 'where it wants to be' target kept separate from 'how it gets there'; exponential damping versus a critically damped spring, with halflife as the tuning unit; velocity look-ahead and an aim lead on its own slow clock; zoom as a product of named factors (player base zoom, wheel, screen size, speed); combat framing that zooms out to keep every threat on screen, with a floor; an optional rotate-with-ship (heading-follow) mode and what it does to the HUD; shake applied only at render and never to the aim; one pair of world/screen conversions; and the camera options players expect. Use when building or reviewing a follow camera, adding zoom or a camera options tab, or when players say 'the view jumped when my mouse came back', 'I got shot from off screen', 'I can't see far enough ahead', 'the zoom makes me sick', 'it's too floaty' or 'too stiff', or 'the arrow points the wrong way'. Shake, punch and the trauma budget are game-feel's.
Ships in dm-game. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Purpose: The camera shows the player what they need to act on, moves without yanking, and lets the player set how it behaves. Feel is a consequence of control done right; game-feel owns punch, shake and the trauma budget.
Sources:
src/view/camera.ts, src/app/focus.ts, camera.test.ts: the pure
target, combat framing, the screen factor, the aim lead. The operator called the auto
zoom-out "a great touch" (felt, via the ice-pirates session).src/rendering/camera-math.ts, camera.ts, hud/settings/settings-types.ts,
camera.test.ts: the exact spring, the settings tab, shake only at render.Math.exp in place of its fastNegExp approximation.Typed sketch: references/camera.ts. It covers the spring, the camera with
framing, heading mode, view() and the conversions, and the aim lead.
| Failure | Root cause | Rule |
|---|---|---|
| The view jumps when the mouse re-enters the window | The aim lead uses the raw pointer, on the follow's clock | 3 |
| Shot by something never on screen | No framing, or framing only the nearest threat | 5 |
| "Too floaty" from one player, "too stiff" from the next | One hard-coded follow rate | 2, 8 |
| A phone sees a third of what a monitor sees | Zoom in pixels, not in world area | 4 |
| The aim drifts during shake | Shake inside the screen→world conversion | 7 |
| An arrow points the wrong way after a zoom | A HUD element doing its own world→screen maths | 7 |
| The camera keeps moving behind the pause menu | The camera runs on raw time | 9 |
cameraTarget(sim, player, lead)
returns { x, y, zoom, frame[], heading }. It never reads the camera.
camera.follow(target, dt).| Mover | Formula | Carries velocity | Use when |
|---|---|---|---|
| Damp (Keren: lerp-smoothing) | x += (goal − x) · (1 − e^(−rate·dt)) | No | Simple follow; zoom |
| Critically damped spring (Keren: physics-smoothing) | redshifted's springDamperExact | Yes | Kicks and zoom pulses as impulses; a smoother start |
x += (goal − x) · 0.1 per
frame is not: it follows twice as tightly at 120 Hz as at 60.r has halflife ln 2 / r, so ice-pirates' 4/s is ~0.17 s. For
redshifted's spring, halflife is a parameter (y = 2 ln 2 / h), not the time to
close half the gap. From rest the spring closes ~40% of the gap in one h and
half at ~1.2 h, so its 0.25 s default takes ~0.3 s to close half (arithmetic on
the formula). Swapping damp for a spring "at the same halflife" gives a camera ~20%
looser.velocity × 1.6 s to the goal.velocity × halflife / ln 2, so at
steady speed the player sits at the centre. Its test proves the zero offset.clamp((aim − player) × 0.15, ±110) world
units, eased by its own damp of 1.6/s (corpus values).
pointerleave on document.documentElement), unless the last-used device is
a pad.zoom = target.zoom × baseZoom (setting) × userZoom (wheel) × screen, then capped by framing (rule 5)
clamp(min(w, h × 1.6) / 1440, 0.6, 1.4) (ice-pirates, corpus
value). A phone, a laptop and an ultrawide then show a comparable world area.
Redshifted doesn't adjust zoom for screen size.userZoom × e^(−deltaY × 0.0012), clamped
0.45–1.8 (ice-pirates, corpus value). Redshifted has none.1 + (zoomMin − 1) × speed/maxSpeed, with
zoomMin 0.6 from a "zoom amount" slider. ice-pirates trims 15%.
zoom *= … scattered through the frame
can't be reasoned about, or turned into a setting.A fairness rule first, a feel bonus second. Keren calls it zoom-to-fit, a multi-focal camera.
threatsTo, corpus value).fit = min((w/2 − 120) / (|dx| + 40), (h/2 − 150) / (|dy| + 40)).
The margins keep the point clear of the HUD edges; size them to your HUD.zoom = min(desired, max(floor, fit)) over all points. The floor bounds the
fit, not the player: a player zoomed out past it stays there. The focus leans 30%
toward the nearest threat (corpus value).UNSOURCED; posture B throughout. Neither corpus game has it, and the operator has asked for it in ice-pirates.
angle = −heading − π/2 in y-down screen space.toScreen, which now rotates. The
compass, edge arrows and markers then rotate correctly without their own maths
(rule 7 covers which of them take the shake).
Anything drawn in screen space with world meaning (a "north" tick, a minimap
heading) needs rotating too.view() carries the angle, and
inView(view, p, grow) rotates the point before comparing. Never use the axis-
aligned box around the rotated screen (bounds() in the sketch) for fair fire: it
covers off-screen corners, so ships the player never saw would count as seen. The
box is for culling only. In a sim, send angle in the player's view input.toWorld excludes it, so shake never moves the aim point (redshifted's
screenToWorld, deliberately). Kicks are velocity impulses into the spring, not
target moves.toScreen(p) is unshaken,
and toScreen(p, true) is for on-object markers. Redshifted's worldToHudScreen
shakes everything, including its edge arrows.x, y, zoom, angle. HUD elements and aim
call toScreen and toWorld; fair fire calls inView; culling uses bounds().
No HUD element does its own maths: the checklist's inView-agrees-with-toScreen
test catches drift.
objective-markers.ts), unlike its edge arrows. That is a likely bug, inferred
from reading the code.view() returns what's on screen in world units ({x, y, hw, hh, angle}) for
fair fire; bounds() returns the axis-aligned box for culling.The options tab, with rows from redshifted's camera tab (corpus) and the gaps noted:
| Option | Redshifted | Note |
|---|---|---|
| Base zoom | Slider 0–1 → 0.5625–1.25 | |
| Follow lag | Slider 0–1 → halflife 0.02–0.25 s | Default 0.25 s (loosest) |
| Spring on/off | Toggle | Off = rigid lock |
| Speed zoom amount, on/off | Slider and toggle | |
| Shake, kick, zoom pulse, hit-stop | Four toggles | No intensity slider |
| Reduced motion | None | Gap: follow settings-and-persistence's tri-state, defaulting to the OS |
| Orientation | n/a | North-up / heading-follow (rule 6) |
redshifted-camera-settings, and clamps each slider on load.dt = 0. Shake then freezes
mid-offset behind the pause menu, still, because the sketch's noise clock advances
by shakeDt too (redshifted's shakeTime does the same). Redshifted does all this. ice-pirates
freezes only the aim lead and passes the real dt to follow; with the sim
frozen the target is still, so the camera just finishes settling and shake keeps
decaying. That's harmless there, but it's the gap a moving target would expose.dt to the shake; the sketch's shakeDt).dt, so both slow and freeze with it (redshifted).dt (redshifted: 0.1 s), so a tab coming back doesn't fling the spring.snap() and zero the velocity. Redshifted has no
snap on restart (inferred, not verified), so its camera presumably springs from
the last position.Toroidal or wrapping worlds: ease toward the shortest wrapped delta, or the
camera takes the long way round (redshifted's wrappedDelta).
Resize: recompute the screen factor and fit on resize. The margins are pixels,
so a tiny window can make w/2 − 120 negative; the floor catches it, but check the
smallest supported window by hand.
Zoom pulses need an integrator. Redshifted's pulses are velocity into the zoom spring; with speed zoom off, zoom is forced to 1 and nothing integrates the velocity, so pulses silently do nothing (inferred from the code, untested).
Phones break the floor rule. Sizing the floor from the longest gun on the smallest window can be unreadable on a landscape phone. Hard Deck (via its session) has a 720 px flak gun and a readability floor of 0.62. On an 852×393 screen, fitting it vertically needs 196.5 / 720 ≈ 0.27 ignoring HUD margins; with rule 5's margins it is (196.5 − 150) / (720 + 40) ≈ 0.06. Either way it's far below readable. The ways out:
hw: 0 clamp; split boards by
device class, or accept it.Pick one per game and write the choice down.
Fit against a moving centre. Fit uses the target centre, not the current camera position, so the framing is right once the camera arrives. While moving, a point near the margin can briefly be off screen; the 40 px pad covers it.
Each line names what the check cannot see.
follow() for 600 frames with two threats on
different axes; both end on screen. Mutation: frame only the first; the test
fails (ice-pirates' camera.test.ts). Blind to: HUD elements covering the
framed point.fastNegExp isn't exact; a port that
keeps it needs a tolerance.toWorld(toScreen(p)) = p with zoom, rotation and shake on
(unshaken toScreen); toScreen(p, true) moves with the shake; toWorld doesn't.inView agrees with
toScreen for points scattered across the box around the screen (and the box
alone would have accepted some off-screen ones); the compass and edge arrows
point at their targets.Three tight links. Everything else routes through the map, so adding a skill
touches one file rather than twenty: references/routing-map.md (in
game-design).
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
40 skills in this plugin
/accessibility-designUse when designing any player-facing feature, evaluating a game for accessibility, responding to accessibility feedback, designing difficulty or assist options, adding subtitle/caption systems, implementing input remapping, or when a player reports they can't play. Covers the four accessibility pillars (visual, auditory, motor, cognitive), implementation tiers, colorblind design, subtitle standards, input accessibility, and testing methodology. Accessibility is a design discipline, not a post-launch checklist./async-and-socialSocial and competitive design that does not require players to be online together: ghost/replay data, leaderboards, asynchronous PvP, offline vulnerability, and anti-snowball mechanics. Use when adding leaderboards or high-score tables, designing ghost races or replay challenges, letting players attack or compete against absent opponents, deciding what social signal a single-player game should carry, or when matches and runs feel decided in the first minutes. Anti-snowball applies to single-player roguelikes and simulations too, not just PvP. For real-time multiplayer architecture, matchmaking, guilds, and moderation, this skill deliberately does not cover them — those are large specialities and belong in dedicated references.npx claudepluginhub rbergman/dark-matter-marketplace --plugin dm-game