Web Games From Zero · Episode 05

Juice & Game Feel

Juice & Game Feel is Episode 05 of Web Games From Zero, a MasterAllArts free interactive lesson for artists learning creative 3D on the web.

Part of the MasterAllArts Creative 3D Roadmap .

Episode 05 · Web Games From Zero

Here is the most uncomfortable secret in game development: a game can be mechanically perfect — correct collision, correct physics, correct rules — and still feel like cardboard. The thing that separates a tech demo from a game you can't put down isn't the simulation. It's the juice: the screen shake when you land a hit, the spray of debris, the little squash of a body absorbing impact, the fraction of a second the whole world freezes on a big one. None of it changes what the game does. All of it changes how the game feels.

This episode is the single most convincing before/after in all of game dev, so we're going to prove it instead of describing it. The demo below is a tiny smasher: a player that hops around and pounds blocks. We add juice one layer at a time across six stages — and at the top of the controls there's one MASTER juice toggle. Flip it off and on while the demo plays. That flip is the whole episode. Juice it, or lose it.

0 fps
▶ playing demo — press any key, or click, to take over
JUICE: ON
Everything on. Toggle MASTER JUICE to feel the difference.

Start on Stage 6 with the demo-AI driving. Now uncheck ✨ MASTER JUICE. Same hops, same hits, same physics — and it instantly looks like a debug build. Check it again. That is the layer this episode is about.

What you're looking at

The simulation underneath every stage is identical and deliberately dumb: a player box falls under gravity, lands on a row of blocks, and on each landing it smashes the block beneath it, which respawns a moment later. The demo-AI just walks the player back and forth and slams down on whatever's below. There is no scoring, no AI to speak of, no difficulty. The mechanic never changes across the six stages or when you toggle juice — only the presentation does. That's the control group. Every difference you see or feel is pure juice, layered on top of a frozen ruleset.

The six stages add one technique at a time so you can isolate what each one buys you:

Stage 1 — The bare action

The honest baseline. The player falls, touches a block, the block vanishes and comes back. It is completely correct and completely dead. Impacts have no weight; the world doesn't react; landing on a block feels exactly like landing on air. This is what almost every prototype looks like on day one, and it's why so many technically-finished games never ship — they feel like this and nobody can say why. Hold this picture in your head. Everything from here is the same game.

Stage 2 — + Screen shake

The cheapest, highest-impact juice there is. On every impact we add a dose of trauma — a single number from 0 to 1. Each frame the camera offsets by a random amount scaled by trauma², and trauma decays back to zero on its own. Suddenly hits have force. The squaring matters: it makes small hits barely wobble and big hits kick hard, and because trauma always decays, the screen always settles. Push the shake slider up and watch how fast it crosses from "punchy" into "nauseating" — restraint is the entire skill here.

Stage 3 — + Particles

Now every smash throws a burst of debris: a dozen little chunks that fly out, fall under gravity, fade, and shrink. Particles are how you say "something just happened here" — they localize the impact in space the way shake localizes it in time. The catch is they're the easiest thing in the engine to leak, so they live in a fixed pool: a pre-allocated array we recycle, never growing, never garbage-collecting mid-frame. Crank the particles slider and the same hit erupts.

Stage 4 — + Squash & stretch + hit-stop

Two classic-animation tricks at once. Squash & stretch: the player stretches tall while falling fast and squashes flat for a few frames on impact, so the body looks like it has mass that compresses. Hit-stop (a.k.a. freeze-frames): on a big landing we freeze the entire simulation for a few dozen milliseconds — update stops, render keeps going — then release. That tiny pause is the difference between a punch that connects and one that whiffs; fighting games and platformers live or die on it. The hit-stop slider scales the freeze; turn it way up and notice how the controls start to feel dead — too much hit-stop eats your inputs.

Stage 5 — + Tweens + camera

Polish. A tween is just a value animated over time through an easing curve; here a scale tween fires on each smashed block and on respawn, driven by easeOutBack so it overshoots and springs back — the "pop" that makes UI and pickups feel candy-like. And the camera stops being nailed down: it smoothly follows the player with a little lag, easing toward its target each frame instead of snapping. A camera that breathes makes the whole frame feel alive even when nothing's being hit.

Stage 6 — ALL juice + the master toggle

Everything together: shake, particles, squash, hit-stop, tweens, follow camera. This is the money shot, and the point isn't the list — it's the ✨ MASTER JUICE toggle. Leave the demo running and flip it off. The game doesn't break; it just dies. The blocks still smash, the player still hops, the physics is bit-for-bit the same. It simply stops feeling like anything. Flip it back on and the life floods back in. Show this toggle to anyone who thinks juice is "just polish" — it's the difference between a product and a prototype, and it costs about a hundred lines.

How the code works

Everything below is plain canvas 2D on the fixed-timestep loop from Episode 01. The golden rule of this episode: all juice is driven by the fixed step or by accumulated time, never by the raw frame delta. Tie shake or decay to a variable dt and your juice runs at a different speed on a 144 Hz monitor than a 60 Hz one. We don't do that.

(a) Screen shake — trauma, trauma² decay, camera offset

One scalar, trauma. Impacts add to it; it decays every fixed step; the camera offset is scaled by its square so the response is non-linear and small knocks stay subtle. Capping trauma at 1 is what keeps a flurry of hits from turning into an earthquake.

let trauma = 0;                              // 0..1, the only shake state
const addTrauma = a => { trauma = Math.min(1, trauma + a); };  // cap at 1 — never an earthquake

// called once per FIXED step, not per frame → frame-rate independent
function decayTrauma() { trauma = Math.max(0, trauma - STEP * 1.5); }

// called at render time; trauma² makes small hits subtle, big hits violent
function shakeOffset(intensity) {
  const t = trauma * trauma;                  // the squaring is the whole trick
  const mag = 22 * t * intensity;             // intensity = slider × juiceOn
  return { x: (Math.random()*2-1) * mag, y: (Math.random()*2-1) * mag };
}
// in render(): ctx.translate(cam.x + s.x, cam.y + s.y) before drawing the world.

(b) The particle burst pool — zero per-frame allocation

A fixed array of particle objects, allocated once. To emit, we find dead slots and revive them; we never push and never create objects in the loop. If the pool is full, the oldest burst simply doesn't spawn — a leak is impossible by construction.

const MAX = 240;                                // hard cap — the anti-leak
const pool = [];
for (let i = 0; i < MAX; i++)
  pool.push({ alive: false, x:0, y:0, vx:0, vy:0, life:0, max:1, size:0, hue:0 });

function burst(x, y, count) {
  for (let n = 0; n < count; n++) {
    const p = pool.find(q => !q.alive);    // recycle a dead slot…
    if (!p) return;                          // …or give up. never grow.
    const a = Math.random() * Math.PI * 2, sp = 60 + Math.random()*220;
    p.alive = true; p.x = x; p.y = y;
    p.vx = Math.cos(a)*sp; p.vy = Math.sin(a)*sp - 80;
    p.life = p.max = 0.4 + Math.random()*0.5;
    p.size = 2 + Math.random()*4; p.hue = 38 + Math.random()*18;
  }
}

function updateParticles() {                   // fixed step → all dt are STEP
  for (const p of pool) {
    if (!p.alive) continue;
    p.vy += 520 * STEP;                       // gravity
    p.x += p.vx * STEP; p.y += p.vy * STEP;
    p.life -= STEP;
    if (p.life <= 0) p.alive = false;       // back to the pool
  }
}

// draw: a chunk fades + shrinks over its life (alpha = life / max)
const a = p.life / p.max;
ctx.fillStyle = 'hsla(' + p.hue + ',85%,62%,' + a + ')';
ctx.fillRect(p.x, p.y, p.size * a, p.size * a);

(c) Squash & stretch + hit-stop

Squash is a scale derived from vertical speed and a decaying impact "punch." Hit-stop is a freeze timer counted down in real time: while it's positive we return out of update() early — physics frozen — but render() keeps drawing, so the frame holds rock-still for a beat.

let freeze = 0;                              // seconds of hit-stop remaining
const hitStop = secs => { freeze = Math.max(freeze, secs); };

function update(dtReal) {
  if (freeze > 0) { freeze -= dtReal; return; }  // FROZEN: skip sim, keep rendering
  // …normal fixed-step physics here…
}

// on landing: stretch→squash. v is signed vertical speed at impact.
function onSmash(v) {
  player.squash = Math.min(0.6, Math.abs(v) / 900);   // how flat to go
  if (Math.abs(v) > 520) hitStop(0.05 * stopScale);   // only BIG hits freeze
  addTrauma(0.45 * shakeScale);
}
// draw: scaleX = 1 + squash, scaleY = 1 − squash (volume-preserving-ish),
// and squash eases back to 0 each step: squash += (0 − squash) * 0.2

(d) An easing tween → the pop

easeOutBack overshoots past 1 and settles back — that little spring is what makes a spawn or a pickup feel alive. A tween is nothing more than a normalized timer fed through the curve.

// overshoots ~10% past the target before settling — the "pop"
const easeOutBack = x => 1 + 2.70158*Math.pow(x-1,3) + 1.70158*Math.pow(x-1,2);

// each block has a spawn timer; advance it on the fixed step
block.t = Math.min(1, block.t + STEP / 0.32);     // 0→1 over 0.32s
const scale = juiceOn ? easeOutBack(block.t) : 1;  // no juice = no pop
// draw the block at (scale × size). Watch it punch in and spring to rest.

// follow camera: ease toward the target instead of snapping (also a tween)
cam.x += (targetX - cam.x) * 0.08;             // per fixed step → smooth, frame-independent

Common pitfalls

  • Too much juice. The number-one beginner mistake once shake is discovered: everything shakes, everything bursts, the screen never holds still and the player gets motion-sick in a minute. Juice is seasoning. Cap your shake (trauma maxes at 1; magnitude is bounded), reserve hit-stop for genuinely big moments, and when in doubt, use less. The sliders in the demo go to "2×" specifically so you can feel where it tips into nauseating.
  • Shake without decay. If trauma only ever goes up, the screen never settles and the game becomes unplayable. Shake must bleed off every step (trauma -= STEP * rate). Decay-to-zero is not optional; it's what makes it "shake" instead of "vibrate forever."
  • Hit-stop too long. A freeze of 40–80 ms reads as impact; a freeze of 300 ms reads as a frame drop, and during it the player's inputs feel eaten because the sim isn't running. Keep it short, scale it with hit magnitude, and never freeze on routine actions. Turn the hit-stop slider to max in the demo to feel exactly how dead long freezes make the controls.
  • Particle leaks. Allocating particles with push in the hit handler — or never removing dead ones — grows an unbounded array, triggers garbage-collection hitches, and eventually tanks the frame-rate mid-fight. Always use a fixed pool with a hard cap and recycle dead slots; if it's full, drop the spawn. Never allocate inside the loop.
  • Juice tied to frame-rate. The sneakiest one. If decay, particle motion, squash recovery, or the camera lerp are multiplied by a variable dt, your juice runs faster on a 144 Hz screen and feels wrong everywhere but your machine. Drive all of it from the fixed step (or real accumulated time for hit-stop) so it feels identical on every display — the same discipline from Episode 01, now applied to feel.

Exercises

  1. Chromatic aberration on big hits. On a heavy smash, draw the world three times — the red channel offset a few pixels left, blue offset right, green centered — with the offset scaled by trauma, so the RGB split snaps apart on impact and heals as trauma decays. (Cheap version: draw the player/blocks twice more with globalCompositeOperation = 'lighten' and small tinted offsets.) It's the single juiciest two-minute addition you can make.
  2. Slow-mo on the final hit. Introduce a global timeScale (default 1). On a designated "finisher" hit, tween it down to ~0.25 and back to 1 over half a second, and multiply your accumulator by it in the loop. Combined with hit-stop you get a cinematic beat. Careful: keep input reading and the FPS counter on real time so the game still feels responsive while the world crawls.
  3. Controller rumble, visualized. Real pads take a rumble pattern — an array of {strength, ms} steps. Build a tiny rumble queue, fire a pattern like [{1,60},{0,40},{0.5,80}] on impact, and visualize it as a pulsing bar at the bottom of the canvas (and, if you like, drive a second tiny shake from it). If you want the real thing, wire it to the Gamepad haptics API behind a feature check.

What's next

Episode 06 — Enemies & AI: something to fight. Juice is wasted on a world that doesn't fight back, so next we give it teeth: spawners, simple steering and state-machine behaviours, line-of-sight and aggro, and contact damage — the targets your newly-juicy hits deserve. All the shake, particles, and hit-stop you just built are about to pay off against things that actually react.