Skip to main content
rule CX Codex

frame-delta-time — Claude Code rule: what it does, how to install

frame-delta-time — a rule that makes every animated movement multiply by delta, so speed stops depending on the display's refresh rate.

MIT ★ 4,719 updated 2026-10-24

Install into Claude Code · Manually: put the files in place All methods and platforms ↓
.claude/rules/frame-delta-time.md
Open on GitHub

What frame-delta-time does

The rule asks for one thing: scale motion by delta. Inside useFrame from react-three-fiber that value arrives as the second argument, the time since the previous frame. A hard-coded 0.01 added to rotation gives you a scene that spins faster on 144 Hz than on 30 fps.

The file walks through the usual cases. Rotation and travel use speed * delta, oscillation reads clock.elapsedTime, smooth following uses a factor of 1 - Math.pow(0.001, delta), and directional movement goes through addScaledVector. There is also a breakdown of the state object: clock, camera, pointer, viewport.

It is a markdown rule, meant for Claude and Codex. Every example sits on useFrame, so a different renderer means porting the pattern by hand. The file itself edits no code; it tells the agent what to write.

What it helps with

  • keep animation speed identical on 144 Hz and 30 fps
  • turn a fixed rotation step into radians per second
  • make a camera follow its target smoothly on any device
  • drive oscillation from clock.elapsedTime instead of a frame counter
  • move an object at a set number of units per second

Example prompts for the agent

  • Rewrite the useFrame callback so rotation is multiplied by delta instead of a fixed step.
  • Check my animation: it should run at the same speed on a 144 Hz screen and on 30 fps.
  • Make the mesh follow its target smoothly with a lerp factor that survives a frame-rate change.

How to install frame-delta-time

Manually: put the files in place

.claude/rules/frame-delta-time.md

The paths frontmatter field limits the files

Step by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use

Questions about frame-delta-time

How do I install frame-delta-time in Claude Code?

Copy the rule to .claude/rules/frame-delta-time.md. That is the whole install.

What does frame-delta-time do?

It tells the agent to scale motion by delta in useFrame, so rotation and movement keep one speed whatever the refresh rate.

What is the difference between delta and clock.elapsedTime?

delta is the gap since the last frame and suits speed. clock.elapsedTime counts from the start and suits oscillations and repeating patterns.

Source text

frame-delta-time.md · MIT
# frame-delta-time

**Always use delta for frame-rate independent animation.**

## Why It Matters

Without delta time, animations run faster on 144Hz displays and slower on 30fps mobile devices. Delta time ensures consistent animation speed regardless of frame rate.

## Bad Example

```jsx
// BAD - Speed varies with frame rate
function BadAnimation() {
  const meshRef = useRef();

  useFrame(() => {
    meshRef.current.rotation.y += 0.01; // Fast on 144hz, slow on 30hz
  });

  return <mesh ref={meshRef} />;
}
```

## Good Example

```jsx
// GOOD - Consistent speed on all devices
function GoodAnimation() {
  const meshRef = useRef();

  useFrame((state, delta) => {
    meshRef.current.rotation.y += 1 * delta; // 1 radian per second, always
  });

  return <mesh ref={meshRef} />;
}
```

## Using Clock for Time-based Effects

```jsx
function TimeBasedAnimation() {
  const meshRef = useRef();

  useFrame(({ clock }) => {
    const t = clock.elapsedTime;

    // Oscillate at consistent frequency
    meshRef.current.position.y = Math.sin(t * 2) * 2; // 2 Hz oscillation
    meshRef.current.position.x = Math.cos(t) * 3;
  });

  return <mesh ref={meshRef} />;
}
```

## Frame-rate Independent Lerp

```jsx
function SmoothFollow({ target }) {
  const meshRef = useRef();

  useFrame((state, delta) => {
    // Frame-rate independent smooth interpolation
    const lerpFactor = 1 - Math.pow(0.001, delta);
    meshRef.current.position.lerp(target, lerpFactor);
  });

  return <mesh ref={meshRef} />;
}
```

## Movement with Speed

```jsx
function MovingObject() {
  const meshRef = useRef();
  const speed = 5; // units per second
  const direction = useRef(new THREE.Vector3(1, 0, 0));

  useFrame((state, delta) => {
    meshRef.current.position.addScaledVector(direction.current, speed * delta);
  });

  return <mesh ref={meshRef} />;
}
```

## Combining Delta and Elapsed Time

```jsx
function ComplexAnimation() {
  const meshRef = useRef();

  useFrame(({ clock }, delta) => {
    const t = clock.elapsedTime;

    // Position based on elapsed time (consistent patterns)
    meshRef.current.position.x = Math.sin(t) * 3;
    meshRef.current.position.z = Math.cos(t) * 3;

    // Rotation based on delta (consistent speed)
    meshRef.current.rotation.y += 0.5 * delta;
  });

  return <mesh ref={meshRef} />;
}
```

## State Destructuring

```jsx
useFrame(({ clock, camera, pointer, viewport }, delta) => {
  // clock.elapsedTime - total time since start
  // clock.getDelta() - same as delta parameter
  // camera - the default camera
  // pointer - normalized mouse position (-1 to 1)
  // viewport - { width, height, factor }
});
```

## References

- [R3F useFrame](https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe)

© zebbern · MIT · zebbern/claude-code-guide

Similar IDE rules

All IDE rules for Frontend and UI →

From the same set86

The whole set →
change-implementer change-implementer — a subagent that carries one pre-approved change through to the end: edits the code, runs it for real, and reports what it observed. CX Codex ★ 4,719repo stars tsl-why-use tsl-why-use — a rule that pushes the coding agent to build custom Three.js materials from TSL nodes rather than patching shaders through onBeforeCompile. CX Codex +1 ★ 4,719repo stars asset-compression Guides your AI coding agent through 3D asset compression for Three.js. Covers Draco, Meshopt, KTX2 textures, and LOD implementation. CX Codex +1 ★ 4,719repo stars perf-never-set-state-in-useframe perf-never-set-state-in-useframe — a react-three-fiber rule that bans setState inside useFrame and pushes you to mutate a ref instead, so animation stops triggering a React render every frame. CX Codex +1 ★ 4,719repo stars draw-call-optimization The draw-call-optimization rule for Claude Code guides Three.js optimization, reducing draw calls to below 100 per frame through instancing, batching, and geometry merging. CX Codex +1 ★ 4,719repo stars object-pooling object-pooling — a rule that pushes the agent to reuse bullets, particles and NPCs from a pool instead of building and discarding meshes every frame. CX Codex +1 ★ 4,719repo stars shader-mobile The shader-mobile rule for Claude Code provides guidelines for optimizing GLSL and Three.js shaders for mobile GPUs to prevent framerate drops on mobile devices. CX Codex +1 ★ 4,719repo stars drei-use-gltf The drei-use-gltf rule guides GLTF loading through useGLTF, including caching and preloading. It fits React Three Fiber scenes that need model assets. CX Codex +1 ★ 4,719repo stars

Project sponsors

Companies that keep this analytics open