What you'll learn
- What easing and tweening mean, and why motion at one constant speed looks robotic while motion that speeds up and slows down feels real.
- The tween recipe: keep elapsed, turn it into a number t from 0 to 1, reshape t with an easing function, and feed the result to THREE.MathUtils.lerp.
- Seven easing functions as one-line formulas you can copy into any project, and how to read their curves: a steep curve means fast, a flat curve means slow, and a curve above 1 means overshoot.
- How to package the recipe as a 20-line Tween class with chaining and yoyo, and when to skip the tween entirely and lerp toward a target instead.
Nothing real moves at one speed
Watch a door swing shut: it starts fast and settles into the frame. Drop a ball: it starts slow and speeds up the whole way down. Open a menu on your phone: it slides in quickly and eases to a stop, never slamming. Real things have weight, and weight means speeding up and slowing down. Now look at what your code has done so far. In Part 7 a cube moved by speed * dt, the same distance every frame, from the first frame to the last. That is how a spreadsheet moves. Nothing in the world starts at full speed and stops dead, so your eye flags it as fake, even if you cannot say why.
Picture two cars at a stop sign. One pulls away the way a real car does: rolling, then gathering speed, then cruising. The other is teleported to 30 miles per hour in a single instant, and later teleported back to zero. Both cars cover the same road in the same time. Only one of them looks like a car. The rule that decides how the speed changes during the trip is called easing, and the whole trip, one value moving from A to B over a set time, is called a tween.
The word tween comes from hand-drawn animation. A lead artist draws the important poses, the key frames, and an assistant draws the frames in between, a job called "in-betweening." Where the assistant puts each in-between decides the feel: bunch them near the start and the motion eases in, bunch them near the end and it eases out. You are about to be the assistant, except your in-betweens are computed by a formula, sixty times a second.
The good news: easing needs no library, plugin, or physics engine. It needs one number that goes from 0 to 1 and a tiny function that bends it, and by the end of this page you will have typed those functions yourself.
Simple definitions: a tween moves one value (a position, an angle, a color, a size) from a start to an end over a fixed duration. An easing function is the rule for how fast that value moves along the way. It takes a number t from 0 to 1 ("how far through the time are we?") and returns a number that is also 0 at the start and 1 at the end, but takes a different route in between.
The recipe, the curves, the helper
The setup from Part 1 and the delta-time loop from Part 7 stay exactly as they were. Everything new is math on plain numbers, and it comes in four short pieces: the tween recipe, the easing formulas, a small class that packages the recipe, and one trick for chasing a target that has no fixed end.
1. The tween recipe
Say the cube should slide from start = -3 to end = 3 in duration = 1.2 seconds. Every frame, add dt to a counter called elapsed. Now the key move: divide elapsed by duration. At the start that gives 0. Halfway through the time it gives 0.5. When the time is up it gives 1, and then it keeps growing, so clamp it with Math.min(..., 1). Call the result t. Whether the duration is 0.3 seconds or 3 minutes, t always runs from 0 to 1 and means the same thing: how far through the tween we are. That is why every easing formula on this page takes t and nothing else. They never need to know how long the tween is.
Next, reshape it: eased = ease(t). For the plainest easing, linear, eased equals t. For easeOutCubic, when t is 0.5 the trip is already 87.5% done, so the second half of the time covers only the last 12.5% of the distance: a fast start and a long, soft stop. Finally, turn that 0-to-1 number into an actual position: start + (end - start) * eased. Multiply the whole distance by the fraction done and add it to where you began. This exact formula is so common it has a name, lerp (linear interpolation), and three.js ships it as THREE.MathUtils.lerp(start, end, eased). Four lines and the cube glides.
// Slide the cube from post A to post B in 1.2 seconds. const start = -3; // where the cube begins (post A) const end = 3; // where it should stop (post B) const duration = 1.2; // seconds for the whole trip let elapsed = 0; // seconds since the tween began function animate() { const dt = Math.min(clock.getDelta(), 0.1); // the delta-time loop from Part 7 elapsed += dt; let t = Math.min(elapsed / duration, 1); // 0 → 1: how far through the TIME we are const eased = easeOutCubic(t); // reshape it: same 0 and 1, different route cube.position.x = THREE.MathUtils.lerp(start, end, eased); // start + (end - start) * eased // when t === 1 the tween is finished: elapsed keeps growing, but t stays 1 and the cube stays at end renderer.render(scene, camera); } renderer.setAnimationLoop(animate);
Read the three middle lines as a pipeline: time becomes t, t becomes eased, eased becomes a position. Only the middle step changes the feel. Swap easeOutCubic for any function below and nothing else moves.
2. Easing functions are tiny formulas
An easing function is a graph. Along the bottom is t, time from 0 to 1. Up the side is ease(t), progress from 0 to 1. Every curve starts at the bottom-left corner and ends at the top-right corner, because every tween starts at the start and ends at the end. What differs is the path between, and the path is a speed chart: where the curve is steep, progress changes a lot per unit of time, so the object is moving fast; where it is flat, the object is nearly still. Linear is a straight diagonal, one speed forever. An ease-in curve starts flat and gets steep; an ease-out curve starts steep and flattens. Once you can read that, you can predict how any easing will feel before you run it.
ease-in
slow start, fast finishFlat then steep. Things that leave: a rocket lifting off, a menu flying off screen, a ball starting to fall.
ease-out
fast start, gentle finishSteep then flat. Things that arrive: a menu sliding in, a card landing, a camera settling. The everyday UI default.
ease-in-out
gentle at both endsAn S shape. Things that go from rest to rest: a drawer, a door, a character turning to look at you.
back & bounce
past the end, then settleThe curve goes above 1 or hits 1 and drops back. Cartoon energy: a button that pops, a coin that bounces.
Now the formulas. Each is one line, and each has a feel you should be able to read from its shape. t * t is small for small t (0.1 becomes 0.01) and catches up late, so it eases in. 1 - (1 - t) * (1 - t) is the same curve flipped, so it eases out. The cubic version uses a power of 3 instead of 2, which makes the fast part faster and the slow part slower: snappier. easeInOutSine uses half a cosine wave to be gentle at both ends. easeOutBack has two magic constants that make the curve rise past 1 to about 1.10 before coming back down, so the object overshoots its target and returns. easeOutBounce is the long one: four pieces of parabola glued together, each a smaller bounce than the last, exactly like a dropped ball. You do not need to invent any of these. They are public formulas every animator uses, published at easings.net, and you can copy them into any JavaScript project, three.js or not.
// Every one takes t from 0..1 and returns progress from 0..1. Straight from easings.net. const linear = (t) => t; // one speed the whole way (robotic) const easeInQuad = (t) => t * t; // slow start, fast finish const easeOutQuad = (t) => 1 - (1 - t) * (1 - t); // fast start, slow finish (the UI default) const easeInOutSine = (t) => -(Math.cos(Math.PI * t) - 1) / 2; // gentle at both ends const easeOutCubic = (t) => 1 - Math.pow(1 - t, 3); // like easeOutQuad but snappier const easeOutBack = (t) => { // overshoots to ~1.10, then settles const c1 = 1.70158; const c3 = c1 + 1; return 1 + c3 * Math.pow(t - 1, 3) + c1 * Math.pow(t - 1, 2); }; function easeOutBounce(t) { // four shrinking bounces, like a dropped ball const n1 = 7.5625; const d1 = 2.75; if (t < 1 / d1) { return n1 * t * t; } else if (t < 2 / d1) { return n1 * (t -= 1.5 / d1) * t + 0.75; } else if (t < 2.5 / d1) { return n1 * (t -= 2.25 / d1) * t + 0.9375; } else { return n1 * (t -= 2.625 / d1) * t + 0.984375; } }
These seven are exactly what the gallery below runs; its graph is drawn by calling each function 120 times with t from 0 to 1 and plotting the answers. A quick sanity check for any easing you write or copy: ease(0) must be 0 and ease(1) must be 1, or the object will not start or end where you told it to.
3. A tiny Tween helper, with chaining and yoyo
The recipe works, but a real game has many tweens at once: a coin spinning, a door opening, a score popping. Copying elapsed and duration variables for each one gets messy fast. So wrap the recipe in a small class. A Tween remembers its own from, to, duration, and ease, keeps its own elapsed, and has one method, update(dt), that runs the recipe once. It does not touch the cube itself. Instead it calls a function you pass in, onUpdate(value), with the new number, and you decide whether that number is an x position, a rotation, a scale, or the volume of a sound. When t reaches 1 it marks itself done and calls onComplete, if you gave it one.
That onComplete is how you build sequences. To make a cube slide over and then spin, you start the spin tween inside the slide tween's onComplete. Chain three or four like that and you have a cutscene. The other option, yoyo, makes a tween reverse when it finishes instead of stopping: swap from and to, reset elapsed, go again. That is a breathing, bobbing, or pulsing loop in one line, and it is exactly what the Yoyo toggle in the gallery does. The whole class is about twenty lines. Libraries such as GSAP and tween.js do precisely this with many more features (delays, timelines, easing on colors), and once you have written your own you will understand every option they offer.
class Tween { constructor({ from, to, duration, ease = linear, onUpdate, onComplete, yoyo = false }) { Object.assign(this, { from, to, duration, ease, onUpdate, onComplete, yoyo }); this.elapsed = 0; this.done = false; } update(dt) { // the recipe from tween.js, once per frame if (this.done) return; this.elapsed += dt; const t = Math.min(this.elapsed / this.duration, 1); const eased = this.ease(t); if (this.onUpdate) this.onUpdate(THREE.MathUtils.lerp(this.from, this.to, eased), t, eased); if (t < 1) return; // still going if (this.yoyo) { // finished: turn around and go again... [this.from, this.to] = [this.to, this.from]; this.elapsed = 0; } else { // ...or stop and tell whoever is waiting this.done = true; if (this.onComplete) this.onComplete(); } } } // Chaining: slide over, THEN spin, by starting the next tween in onComplete. let tweens = []; tweens.push(new Tween({ from: -3, to: 3, duration: 1.2, ease: easeOutCubic, onUpdate: (x) => { cube.position.x = x; }, onComplete: () => { tweens.push(new Tween({ from: 0, to: Math.PI, duration: 0.6, ease: easeOutBack, onUpdate: (angle) => { cube.rotation.y = angle; }, })); }, })); // Yoyo: a pet that "breathes" forever, 1 → 1.15 → 1 → 1.15 ... tweens.push(new Tween({ from: 1, to: 1.15, duration: 0.8, ease: easeInOutSine, yoyo: true, onUpdate: (s) => { pet.scale.setScalar(s); }, })); function animate() { const dt = Math.min(clock.getDelta(), 0.1); for (const tw of tweens) tw.update(dt); tweens = tweens.filter((tw) => !tw.done); // forget the finished ones renderer.render(scene, camera); }
The gallery's cube is driven by this exact class: Play makes a new Tween from post A to post B, the Yoyo toggle sets its yoyo, and onUpdate also receives t and eased so the graph and the live code can show them. Notice that onUpdate gets called one last time with t === 1 before anything else happens, so the value always lands exactly on to.
4. Lerp toward a target: the tween with no duration
Sometimes there is no "end" to tween to, because the goal keeps moving: a camera following a player, a pet trotting after the cursor, a health bar catching up to the real number. For those, drop the duration and use the trick you met in Part 9: every frame, move a fraction of the remaining distance toward the target. position.lerp(target, 0.1) closes 10% of the gap each frame. Because the gap shrinks, each step is smaller than the last, so the motion eases out automatically and it can never overshoot. It also never quite arrives; the gap just gets too small to see, which is fine.
The catch is that "10% per frame" is 6 gap-fractions per second at 60 fps and 14 at 144 fps, the per-frame bug from Part 7 in disguise. The fix is to write the fraction in terms of dt: 1 - Math.pow(0.001, dt). Read 0.001 as "the share of the gap still left after one full second," a tenth of a percent. Raising it to the power dt gives the share left after this frame, whatever length the frame was, and one minus that is how much to move. Bigger base (say 0.1) means a lazier follower; smaller means a snappier one. So you have two tools: a tween when you know where and when something should stop, and lerp toward a target when it should keep chasing something that moves.
// No duration and no end time: every frame, close part of whatever gap is left. const target = new THREE.Vector3(0, 0.4, 0); stage.addEventListener('pointermove', () => { // mouse.x and mouse.y are the -1..1 numbers from Part 10; stretch them across the floor target.set(mouse.x * 4, 0.4, -mouse.y * 2.5); }); function chase(dt) { ball.position.lerp(target, 1 - Math.pow(0.001, dt)); // same feel at 30, 60, or 144 fps }
chase(dt) runs inside animate. The gallery's "Lerp toward mouse" mode is this code, with the 0.001 on a slider. Mapping the mouse straight onto the floor is a shortcut; Part 16 does it properly by shooting a ray from the camera.
The easing gallery
The cube slides from post A to post B using whichever easing you pick. Beside it, the graph draws that easing's curve, and the dot on the curve is the cube right now: its x position is the current t, its height is eased. Whenever the dot is climbing a steep part of the curve, the cube is moving fast; on a flat part it crawls. Press Play to run the tween again from A. The live code under the controls shows the recipe's three lines with their real values.
Loading 3D preview…
easeOutCubic · t = 0.00 · eased = 0.00the curve
Graph: across is t (time, 0 to 1), up is eased (progress, 0 at A to 1 at B). Steep means fast. Above the dashed B line means overshoot.
tween.js
chase.js
t = Math.min(elapsed / duration, 1); // elapsed 0.00 s / duration 1.20 s → t = 0.00 const eased = easeOutCubic(t); // eased = 0.00 cube.position.x = THREE.MathUtils.lerp(-3, 3, eased); // x = -3.00 // extras off: only position.x is tweened
target.set(mouse.x * 4, 0.4, -mouse.y * 2.5); // target x = 0.00, z = 0.00 ball.position.lerp(target, 1 - Math.pow(0.001, dt)); // gap left: 0.00 units
- Pick Linear, press Play, then pick Out Cubic at the same duration. Both trips take exactly 1.20 seconds, but watch where the cube spends its time. Linear spends it evenly, and the dot slides up a straight line. Out Cubic is already past the middle of the track when t reads 0.25, then spends more than half the time creeping over the last stretch. On the graph that is a steep start and a long flat tail.
- Pick Out Back and watch the cube reach post B. It passes the post, stops, and comes back to it. Now find that moment on the graph: the curve climbs above the dashed B line, to about 1.10, then drops back down to 1. eased can be bigger than 1 even though t never is. Turn on Also ease scale/rotation and notice that the turn and the squash overshoot too, because they read the same eased number.
- Set Duration to 3 s, pick In Quad, and press Play. Count how long the cube "hesitates" near post A before it visibly gets going: t * t is only 0.0625 when a quarter of the time is gone, so the cube has covered about 6% of the track after 0.75 seconds. Then switch to Lerp toward mouse, move the pointer around the stage, and slide Chase speed left to a base near 0.3. The ball turns lazy and the gap readout shrinks slowly. Slide it right and the ball snaps to your pointer; there is no duration anywhere, only "how much of the remaining gap per second."
Common mistakes
Easing bugs are sneaky because the object usually does end up in the right place. It just gets there wrong. Each of these four has a one-line cause and a one-line fix.
You add a constant to the position every frame and wonder why it looks robotic. Adding the same amount each frame is linear easing, and because it is per frame rather than per second, it is also faster on faster screens (Part 7).
Fix: keep an elapsed counter in seconds, compute t = Math.min(elapsed / duration, 1), and set the position from lerp(start, end, ease(t)). Never "nudge" the position toward the goal by a constant.
Without Math.min(..., 1), t keeps growing after the duration ends and the value shoots past the end forever. With easeOutBack or easeOutBounce it is worse: those formulas are only meaningful on 0..1, and at t = 2 they return nonsense.
Fix: always clamp before easing, and treat t === 1 as the "done" signal. The last onUpdate then lands exactly on to, no matter how long the frame was.
Your follower feels perfect on your laptop and twice as eager on a friend's 120 Hz monitor. A fixed fraction per frame closes the gap at a rate that depends on the frame rate.
Fix: write the fraction from dt: position.lerp(target, 1 - Math.pow(0.001, dt)). The 0.001 is the share of the gap left after one second, on every device.
A panel is halfway through sliding in when the user taps again. Your code starts a new tween from the original start, so the panel jumps back to where it began and slides in a second time.
Fix: when a tween is interrupted, start the new one from the current value: from: panel.position.x, not from: -3. The gallery's Play button resets to A on purpose so you can compare curves; a real menu should not.
Check your understanding
A menu panel should slide in from the edge of the screen and settle gently into place. Which easing family would you pick, and what does t equal at the moment the panel should stop?
Your answer:
Sample answer: an ease-out, such as easeOutCubic or easeOutQuad, because things that arrive should start fast and slow down as they land. The panel stops when t equals 1 (clamped), which is when elapsed has reached duration and the tween is complete; eased is also 1 there, so lerp returns exactly end.
Quick quiz
1. In the tween recipe, what does t represent?
2. Which easing makes the cube pass its target and come back before settling?
3. A friend animates a door with door.rotation.y += 0.1 every frame until it reaches its angle. What is wrong with it?
Keep learning
You can now make anything glide, pop, or bounce with a number from 0 to 1 and a one-line formula: build t from elapsed / duration, reshape it with an easing function, hand it to lerp, package that as a Tween with chaining and yoyo, and reach for lerp-toward-a-target when the goal keeps moving. Next, you go from one moving object to thousands: particle systems for stars, snow, and fountains.
Part of the Games and Animations with Three.js tutorial series.