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
.claude/rules/frame-delta-time.mdWhat 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.elapsedTimeinstead of a frame counter - move an object at a set number of units per second
Example prompts for the agent
- Rewrite the
useFramecallback so rotation is multiplied bydeltainstead 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.mdThe paths frontmatter field limits the files
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.cursor/rules/frame-delta-time.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.github/instructions/frame-delta-time.instructions.mdThe applyTo field sets which files it applies to
Manually: put the files in place
.devin/rules/frame-delta-time.mdManually: put the files in place
.clinerules/frame-delta-time.mdStep 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