Feature Library

Game feel for 2D: shake, hit-stop and a follow camera

0.23 CPU ms
A still of the Game feel for 2D: shake, hit-stop and a follow camera demo
Still
The live demo starts when it’s in view.Move with WASD, the arrow keys or a press on the arena · Space or Impact hits everything near · sliders change the feel

Three small pieces that make hits land in a 2D action game.

A trauma shake: knocks add trauma, which decays, and the offset is its square on a smooth sum of sines, so small knocks stay small and big ones shudder; it stops entirely when motion is reduced. A hit-stop: a few hundredths of a second where the simulation holds while effects, sound and camera run on. A camera that follows with a lead toward where the player heads or aims, eases in, stays inside the world and snaps on a new round.

See it live in Swarm run, the 2D action kit’s game →

What it costs a frame

0.23 ms
GPU
not used
CPU, median
0.23 ms
CPU, 95th pct
0.36 ms
Draw calls
0
Weight
Light

Measured 21 November 2026 on RTX 4060 Laptop, 13th Gen Intel(R) Core(TM) i9-13900H, Chrome 157, 1920×1080 at 1×. 600 frames × 3 rounds, median kept (rounds ranged CPU 0.21–0.23 ms). What ran: Alone, with the player circling the arena on its own and an impact every 0.7 s: the shake, the hit-stop and the follow camera each frame over a plain grid with the impact rings, in Canvas 2D. Phones: tiers are being measured next.

How steadily it runs on RTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900H · reference

Typical frame ?
16.86 ms
1% low ?
52 fps
Varies by ?
±0.53 ms
All metricsRTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900H · reference
p50p95p9916.07 ms19.55 ms +
How long each frame took. Most frames sit in the tall bars; a long tail to the right is hitching.

Frames run on a 60 Hz timer (a page demo), so most frames take about one tick, 16.7 ms: the spread around it is what matters.

Frames

Median (p50) ?
16.86 ms
p95 ?
17.97 ms
p99 ?
18.63 ms
Slowest ?
20.25 ms
Mean ?
16.91 ms
Standard deviation ?
0.53 ms
1% low ?
52 fps
0.1% low ?
49 fps
Hitches ?
0 of 600
Over budget ?
0 of 600

Main thread

Long tasks ?
0
Long frames ?
0
Event-loop delay ?
0.1 / 0.8 / 1.3 ms

Input

No input during this run.

Memory

JavaScript heap ?
33.8 → 35.9 MB
Growth ?
+2.15 MB

Browser

JavaScript a frame ?
0.35 ms
All tasks a frame ?
0.91 ms
Layout / style ?
0.08 / 0.02 ms
Main thread busy ?
5%

Garbage collection

Collections ?
2 (2 minor, 0 major)
Pauses ?
2.0 ms in all, longest 1.3

What it needs

Renders with
Canvas 2DA 2D canvas: every current browser.
Your browser
Runs hereNo WebGPU needed
Depends on
NothingNo other packages
With an agent
install("game-feel-2d")Your coding agent reads its pitfalls and installs it through the library’s MCP server. Set it up

What it’s for

  1. Twin-stick, swarm and arena games
  2. Platformers and brawlers that need hits to land
  3. A camera that leads the player in a scrolling 2D world
  4. A calm mode that keeps the game but drops the shaking
  5. Top-down maps and boards that follow a selection

Pitfalls, in brief

  1. Reduced motion must stop the shake, not soften it: pass motion as the page’s live Motion switch (or the reduced-motion preference), read every frame.
  2. Kick small: trauma is squared, so 0.1 to 0.2 is a nudge, 0.3 a blast, 0.7 a boss.
  3. The shake is a screen offset in pixels: add it after the camera’s transform (a translate on the canvas), not to the camera’s world position, or it scales with zoom and the follow eases it away.
  4. Hit-stop holds the simulation, not the frame: keep drawing, effects, sound and the camera running, or it reads as a stall.
  5. Run the simulation on the dt that take() gives back.
2 more in brief
  1. The lead is in world units: scale it from movement or aim (a unit vector times 60 to 120), and ease it, or the view jumps when the stick flicks.
  2. A camera whose bounds are smaller than the view along an axis centres on them: that is right for a small arena, but give a scrolling world bounds at least the view’s size.
7 pitfalls in full, the hook-up guide, the module source and its tests come with the part.

Where it comes from

From another of the maker’s apps. Fully custom code.

Squirrel Eiserloh, “Juicing your cameras with math” (GDC 2016): Trauma that decays, with the shake as its square. The idea, not code.

gamegame feeljuicescreen shaketraumahit-stophit pausefreeze framecamerafollow cameralook-aheadcamera boundsreduced motioncanvas 2dheadlessno dependencies

Near it in the frame