smooth-interpolation
Installation
SKILL.md
Smooth Interpolation
Animate values smoothly using exponential decay instead of linear interpolation.
Technique
Use exponential smoothing formulas to interpolate between current and target values. This creates a natural easing effect that's frame-rate independent.
Key Concepts
- Exponential smoothing:
(target - current) * (1 - Math.exp(-speed * dt)) - Exponential decay:
target + (current - target) * Math.exp(-decay * dt) - Both formulas produce the same result with different parameters
- Speed/decay values from 1-25 work well
- Frame-rate independent due to delta time usage
Usage
const addSmoothExp = (current: number, target: number, speed: number, dt: number) =>
(target - current) * (1 - Math.exp(-speed * dt))
const expDecay = (current: number, target: number, decay: number, dt: number) =>
target + (current - target) * Math.exp(-decay * dt)
useFrame((_, delta) => {
mesh.position.x += addSmoothExp(mesh.position.x, targetX, 3, delta)
// or
mesh.position.x = expDecay(mesh.position.x, targetX, 3, delta)
})
References
This skill is part of verekia's r3f-gamedev.
Related skills
More from verekia/r3f-gamedev
ui-useframe
Sync UI elements outside the Canvas with the render loop using R3F v10's external useFrame.
8r3f-setup
Set up a React Three Fiber project with WebGPU support.
7reactive-polling
Poll for changes to any value and trigger React re-renders when it changes.
7miniplex
Use Miniplex for minimalistic Entity Component System with TypeScript support.
6bone-attachment
Attach meshes to bones of a skinned mesh, such as attaching a sword to a character's hand.
6verekia-architecture
Day-to-day coding style and patterns for R3F game development with Miniplex ECS.
6