# Procedural Gait, Chain Motion & Readable Impact VFX in Pulse

> Expressive creature locomotion and impact readability in Pulse using ProceduralMotion, ProceduralGait, ProceduralChain, deterministic hit-flash/recoil components, and layered vfx bursts.

- **Canonical page:** https://gamecrew.ai/techniques/pulse/procedural-motion-combat-vfx
- **Techniques hub:** https://gamecrew.ai/techniques
- **Engine:** Pulse
- **Category:** animation
- **Tags:** `procedural-motion`, `gait`, `chain`, `vfx`, `combat`, `hitstop`, `animation`, `deterministic`
- **Verification:** Compile-verified pattern

## When to Use & Field Best Practices

Even before custom 3D rigged models are imported, Pulse games can achieve expressive creature motion and crisp combat/platforming feedback by combining Pulse's built-in procedural animation components with deterministic recoil and impact VFX:
- **`ProceduralMotion`**: Gives floating orbs, idols, lanterns, and idle NPCs continuous breathing, bobbing, and velocity-driven lean with zero script boilerplate.
- **`ProceduralGait` & `ProceduralChain`**: Drives multi-legged walkers (spiders, crabs, striders) and trailing tails/banners/tentacles physically aligned to ground terrain.
- **Deterministic Recoil & Hit-Flash**: Pair `vfx("shockwave" | "burst" | "spark", ...)` + `shake(amount)` + `sfxAt(cue, pos)` on the exact impact tick so every hit reads in audio, motion, and capture frames simultaneously.

## Mathematical & Algorithmic Core

- **Knockback Impulse**: Compute horizontal unit push $\hat{\mathbf{d}} = \mathrm{normalize}(\mathbf{p}_{\text{target},xz} - \mathbf{p}_{\text{source},xz})$ with deterministic fallback $(0, 0, 1)$ when $\|\Delta \mathbf{p}_{xz}\| < 10^{-4}$ (never divide by zero!).
- **Exponential Recoil Recovery**: $r_{t+1} = r_t \cdot \max(0, 1 - k \Delta t)$ keeps recovery smooth across any tick rate `hz`.

## Engine Implementation

### 1. Prefab Composition with `ProceduralMotion` & `ProceduralChain` (`prefabs/sentinel.prefab.jsonc`)

```jsonc
{
  "tags": ["enemy", "sentinel"],
  "components": {
    "Mesh": { "primitive": "capsule", "w": 0.9, "h": 1.6, "d": 0.9, "color": "#3b4259", "emissive": "#ff6a3d", "roughness": 0.35, "metallic": 0.5 },
    "Body": { "kind": "kinematic", "shape": "capsule", "radius": 0.45, "h": 1.6 },
    "ProceduralMotion": { "bob_amp": 0.08, "bob_hz": 1.4, "lean_deg": 8.0 },
    "Light": { "kind": "point", "r": 1.0, "g": 0.42, "b": 0.24, "intensity": 1.8, "range": 5.5, "cast_shadows": false }
  }
}
```

### 2. Deterministic Impact, Knockback & Layered VFX System (`systems/impact.ts`)

Declare via `pulse_declare`:
- `"component HitRecoil { timer_s: num=0.0, push_x: num=0.0, push_z: num=0.0 }"`
- `"event ImpactHit { target: entity, from_x: num, from_z: num, power: num }"`

```ts
import { events, query, sfxAt, shake, system, vfx } from "pulse";
import { HitRecoil, ImpactHit } from "../contracts/combat";

export const impactSystem = system("impact", { after: "physics" }, (dt) => {
  for (const ev of events(ImpactHit)) {
    const t = ev.target;
    if (!t || !t.has(HitRecoil)) continue;
    const dx = t.pos[0] - ev.from_x;
    const dz = t.pos[2] - ev.from_z;
    const len = Math.hypot(dx, dz);
    const nx = len > 1e-4 ? dx / len : 0.0;
    const nz = len > 1e-4 ? dz / len : 1.0;

    t.hitRecoil.timer_s = 0.18;
    t.hitRecoil.push_x = nx * ev.power;
    t.hitRecoil.push_z = nz * ev.power;

    const hitPos: [number, number, number] = [t.pos[0], t.pos[1] + 0.8, t.pos[2]];
    vfx("spark", { pos: hitPos, color: "#ffd27d", count: 14 });
    vfx("shockwave", { pos: hitPos, color: "#ff7847", count: 1 });
    sfxAt("hit", hitPos);
    shake(0.24);
  }

  for (const e of query(HitRecoil)) {
    const r = e.hitRecoil;
    if (r.timer_s <= 0.0) continue;
    r.timer_s = Math.max(0.0, r.timer_s - dt);
    const decay = Math.max(0.0, 1.0 - 9.0 * dt);
    e.vel = [r.push_x, e.vel[1], r.push_z];
    r.push_x *= decay;
    r.push_z *= decay;
  }
});
```

## Browser, Mobile & Software-Renderer Budgets

- **Point Light Shadows**: Set `cast_shadows: false` on enemy/pickup `Light` components; reserve shadow maps for the directional sun so WebGPU mobile and headless browser checks stay fast.
- **Audio Cue Rule**: Only call `sfxAt("hit", ...)` when `Assets/Game/Resources/Audio/hit.wav` exists in the project.

## Verification Checklist

1. Run `pulse_run` on a combat scenario and verify `ImpactHit` + `played(hit)` expectations pass.
2. Run `pulse_look` `"clip <scenario>"` to inspect the 4×3 contact sheet of the impact burst and knockback arc.

## Official references

- David Rosen (GDC 2014 — Overgrowth Procedural Animation Bootcamp)
- Masahiro Sakurai (Impact Framing & Recoil)
- Pulse Procedural Components & VFX Reference
