GameCrew AIEarly access
Sign in
Unity 6gameplayCompile-verified pattern

Frame-Rate-Independent Procedural Springs, Squash-Stretch & Trauma Feel in Unity 6

Exact dt-invariant second-order critically/under-damped spring dampers, Squirrel Eiserloh T^2 rotational Perlin camera trauma, volume-preserving squash-and-stretch, and TestClock-safe hit-stop.

  • springs
  • game-feel
  • juice
  • camera-shake
  • trauma
  • squash-stretch
  • hitstop
  • animation
  • physics

When to Use & Field Best Practices

Games feel stiff or fragile when motion uses linear MoveTowards or broken frame-dependent Lerp(a, b, 0.1f) (which runs at completely different speeds at 30 Hz, 60 Hz, and accelerated PlayMode TestClock steps!). Every responsive platformer, brawler, or arcade slice benefits from four composable math primitives:

  1. Δ t-Invariant Exponential Decay & Second-Order Springs: Parameterize springs by human-intuitive frequency $f$ (Hz) and damping ratio zeta (zeta = 1: crisp zero-overshoot camera follow; zeta ∈ [0.35, 0.6]: bouncy UI popups, weapon recoil, landing squash).
  2. Volume-Preserving Squash & Stretch: When vertical scale compresses to s_y on jump takeoff (s_y = 1.28) or landing impact (s_y = 0.74), set s_x = s_z = 1 / √s_y on the visual child transform only (never scale a CharacterController or Collider!).
  3. Trauma T^2 Rotational Camera Shake (Eiserloh, GDC 2016): Accumulate scalar trauma ∈ [0, 1] from impacts (+0.25 to +0.6), decay linearly at sim 1.4/s, and drive rotational pitch/yaw/roll offsets proportional to trauma^2 via smooth Mathf.PerlinNoise (never Random.insideUnitSphere jitter, and never translate camera position through walls).
  4. TestClock-Safe Hit-Stop: Pause or slow a local simulation timer (_hitStopRemaining -= Time.deltaTime) on melee/heavy impacts instead of mutating global Time.timeScale, because accelerated PlayMode tests (test-clock.json) drive Time.timeScale themselves!

Mathematical & Algorithmic Core

### Semi-Implicit Symplectic Spring with Substep Clamp For angular frequency ω = 2π f and damping ratio zeta ≥ 0: $a = -ω^2 (x - x_target) - 2zetaω v$ Substepping $\Delta t$ into steps $\le \min(\Delta t, \frac{1}{4 f \pi})$ guarantees unconditional stability even during hitches or fast-forwarded TestClock ticks while remaining 10 lines of allocation-free code.

### Volume-Preserving Deformation $V = s_x · s_y · s_z = 1 implies s_x = s_z = frac1√max(0.35, s_y)$

Engine Implementation

Reusable Zero-Allocation Feel Primitives (Assets/Game/Runtime/Core/SpringFeel.cs)

using UnityEngine;

namespace Game.Core
{
    public struct FloatSpring
    {
        public float Value;
        public float Velocity;

        public FloatSpring(float initial)
        {
            Value = initial;
            Velocity = 0f;
        }

        public float Step(float target, float frequencyHz, float dampingRatio, float dt)
        {
            if (dt <= 0f) return Value;
            float omega = 2f * Mathf.PI * Mathf.Max(0.1f, frequencyHz);
            float maxStep = Mathf.Min(0.016f, 0.5f / Mathf.Max(1f, omega));
            float remaining = Mathf.Min(dt, 0.2f);
            while (remaining > 1e-5f)
            {
                float h = Mathf.Min(remaining, maxStep);
                float accel = -omega * omega * (Value - target) - 2f * dampingRatio * omega * Velocity;
                Velocity += accel * h;
                Value += Velocity * h;
                remaining -= h;
            }
            return Value;
        }

        public void Impulse(float velocityDelta) => Velocity += velocityDelta;
    }

    public struct Vector3Spring
    {
        public Vector3 Value;
        public Vector3 Velocity;

        public Vector3Spring(Vector3 initial)
        {
            Value = initial;
            Velocity = Vector3.zero;
        }

        public Vector3 Step(Vector3 target, float frequencyHz, float dampingRatio, float dt)
        {
            if (dt <= 0f) return Value;
            float omega = 2f * Mathf.PI * Mathf.Max(0.1f, frequencyHz);
            float maxStep = Mathf.Min(0.016f, 0.5f / Mathf.Max(1f, omega));
            float remaining = Mathf.Min(dt, 0.2f);
            while (remaining > 1e-5f)
            {
                float h = Mathf.Min(remaining, maxStep);
                Vector3 accel = -omega * omega * (Value - target) - 2f * dampingRatio * omega * Velocity;
                Velocity += accel * h;
                Value += Velocity * h;
                remaining -= h;
            }
            return Value;
        }
    }

    public struct CameraTrauma
    {
        private float _trauma;
        private float _seed;

        public float Trauma => _trauma;

        public void Add(float amount)
        {
            if (_seed == 0f) _seed = 17.3f;
            _trauma = Mathf.Clamp01(_trauma + Mathf.Max(0f, amount));
        }

        public Quaternion SampleRotation(float dt, float time, Vector3 maxAnglesDeg, float frequency = 22f, float recoveryPerSec = 1.45f)
        {
            _trauma = Mathf.Max(0f, _trauma - recoveryPerSec * Mathf.Max(0f, dt));
            float shake = _trauma * _trauma;
            if (shake <= 1e-4f) return Quaternion.identity;

            float t = time * frequency;
            float pitch = (Mathf.PerlinNoise(_seed, t) * 2f - 1f) * maxAnglesDeg.x * shake;
            float yaw   = (Mathf.PerlinNoise(_seed + 31.7f, t) * 2f - 1f) * maxAnglesDeg.y * shake;
            float roll  = (Mathf.PerlinNoise(_seed + 73.1f, t) * 2f - 1f) * maxAnglesDeg.z * shake;
            return Quaternion.Euler(pitch, yaw, roll);
        }
    }

    public static class SquashStretch
    {
        public static Vector3 PreserveVolume(float scaleY, Vector3 baseScale)
        {
            float clampedY = Mathf.Clamp(scaleY, 0.45f, 1.85f);
            float invSqrt = 1f / Mathf.Sqrt(clampedY);
            return new Vector3(baseScale.x * invSqrt, baseScale.y * clampedY, baseScale.z * invSqrt);
        }

        public static float ExpDecay(float current, float target, float decayPerSec, float dt)
        {
            return target + (current - target) * Mathf.Exp(-decayPerSec * Mathf.Max(0f, dt));
        }
    }
}

### Applying Squash-Stretch + Trauma Cleanly

  • Character Visual Child: Keep Player root (CharacterController) at Vector3.one. Put the mesh/model under a Visual child transform:
  • On Jump: _squashSpring.Impulse(+4.5f) (stretches vertically to ~1.25, narrows XZ to ~0.89).
  • On Land (!wasGrounded && grounded): _squashSpring.Impulse(-Mathf.Clamp(impactSpeed * 0.45f, 2f, 6.5f)).
  • Each Update: visual.localScale = SquashStretch.PreserveVolume(_squashSpring.Step(1f, 6.5f, 0.45f, Time.deltaTime), _baseScale);
  • Camera Rig: Compute clean orbit/follow rotation first, then post-multiply camera.transform.localRotation = baseRot * _trauma.SampleRotation(Time.deltaTime, Time.time, new Vector3(3.5f, 3.5f, 2.0f));.

Browser, Mobile & Software-Renderer Budgets

  • Zero GC Allocations: FloatSpring, Vector3Spring, and CameraTrauma are value-type structs with zero heap allocations per frame.
  • TestClock Determinism: Never touch Time.timeScale for hit-stop (test-clock.json runs PlayMode tests at accelerated Time.timeScale); instead gate enemy/player simulation ticks on a local _hitStopTimer > 0f decremented by Time.deltaTime.

Verification Checklist

  1. Write an EditMode unit test proving FloatSpring.Step converges to target within 0.005f for both dt = 1f / 30f (30 steps) and dt = 1f / 120f (120 steps) over 1.0 second.
  2. Run record_test on jumping/landing and inspect the contact sheet to verify visible takeoff stretch and landing squash without collider snagging.

Official references

  • Squirrel Eiserloh (GDC 2016 — Math for Game Programmers: Juicing Your Cameras With Math)
  • Ryan Juckett (Damped Springs)
  • Theodoros & Freya Holmér (Frame-Rate Independent Damping)
  • Masahiro Sakurai (Hit-Stop / Freeze Frames)

Playable Unity 6 games made with GameCrew

Launch a real browser build using this engine and inspect its controls or fork its project tree.

Kerbside — Every push, pop and scrape is earned: a grounded skateboarding game where your feet, not a button, do the trick, and a clean landing feels like the real thing.

Kerbside

Every push, pop and scrape is earned: a grounded skateboarding game where your feet, not a button, do the trick, and a clean landing feels like the real thing.

Fjordline — Leap from a granite wall under the midnight sun and carve one unbroken wingsuit line through Norway's most dramatic landscapes, from summit to sea, skimming close enough to touch the rock.

Fjordline

Leap from a granite wall under the midnight sun and carve one unbroken wingsuit line through Norway's most dramatic landscapes, from summit to sea, skimming close enough to touch the rock.

More Unity 6 techniques

lighting

Atmospheric Height Fog, Sun Shafts & Rim-Readable Lighting in Unity 6 URP →

Three-point outdoor/interior URP lighting recipe combining directional sun + warm/cool fill, exponential height/distance fog, ACES/Neutral post-processing, and anti-darkness floors so captures never read black or washed out.

shaders

Cel-Shading, Shadow Ramps & Width-Compensated Outlines in Unity 6 URP →

Two-pass URP stylized cel shader combining main-light shadow-attenuated diffuse ramps, crisp specular/rim accents, and clip-space distance-compensated inverted-hull outlines.

physics

CharacterController Slope Projection & Floor Snap in Unity 6 →

Deterministic Unity 6 CharacterController locomotion with SphereCast ground projection, ramp stickiness, steep-slope slide, and coyote jumps.

ai

Context Steering, Telegraphed Combat & Attack-Token Encounters in Unity 6 →

Readable enemy and companion AI in Unity 6 using 8-ray context steering maps, FOV + line-of-sight hysteresis, telegraph/active/recovery state machines, and an encounter attack-token director.

Use verified techniques inside a real game

Describe your game idea for free or connect an MCP assistant to search and contribute techniques.

Learn about collaboration