Chaining and Interrupting Motion
When one motion hands off to another, two things have to line up at the switch: where the object is, and how fast it's going. Matching position alone (C⁰) avoids a teleport but still jolts; matching velocity too (C¹) makes the handoff invisible, and for an interrupted tween that means starting the new motion from the current position and the current velocity.
What the symbols mean
- First duration
How long the first tween, from a to b, takes.
- Second duration
How long the second tween, from b to c, takes.
What the symbols mean
- Current position
Where the object is at the moment of the switch.
- Current velocity
How fast it is moving at that moment, in units per second.
- Fraction of the new tween
Seconds since the switch divided by T.
- New duration
How long the new motion takes.
What the symbols mean
- New target
Where the motion should end.
- Distance left over
How far the target is beyond where the current velocity alone would carry the object in time T.
Explanation
Chaining motion means playing one tween right after another, and interrupting means changing a motion's target while it's still running, like tapping "close" on a drawer that's halfway open. (A tween is one eased move from a start to an end; the word comes from the animator's in-betweens, the drawings between two key poses.) Both times the question is what happens at the handoff. The position must line up, or the object teleports. The velocity should line up too, or it jolts. A handoff is called C⁰ when position is continuous and C¹ when velocity is continuous as well, the same labels used for joining curves smoothly. It sounds technical, but it comes down to two numbers at the moment of the switch: where the thing is and how fast it's going.
The velocity of a tween. From Timing: Why Motion Needs Easing, a tween from to over seconds moves at . So its velocity at each end comes from the easing's end slopes: ease-in quad leaves at and arrives at ; ease-out quad leaves at and arrives at ; every ease-in-out leaves and arrives at .
Chaining. Two tweens back to back are always C⁰, since the second starts where the first ended. They're C¹ only if the first one's arriving velocity equals the second one's leaving velocity. Two ease-in-outs meet at velocity , so the object stops at the joint. That's right for "move, pause, move", and wrong for a camera that should glide through a waypoint. To glide through, ease in to the waypoint and ease out of it, and choose the durations so the speeds match. With quad on both legs, , which says simply that both legs have the same average speed.
Interrupting. A drawer is opening with ease-out cubic, and halfway through its time the user taps "close". The obvious code starts a new ease-out tween from wherever the drawer is now back to closed. The position is fine (C⁰), but the velocity jumps: the drawer was moving outward and instantly moves inward at ease-out's full starting speed. The eye reads that as being hit. (Restarting from the original start position is worse: that's a teleport.)
The fix is to start the new motion from the current position and the current velocity. A cubic has four coefficients, exactly enough for four conditions: start at , start with velocity , end at , end at rest. Measure time in the new tween with , the fraction of its duration that has passed since the switch at , and write
The first two coefficients are forced: , and since , starting at velocity means . The other two come from the end:
Let , the distance still to cover beyond what the current velocity would carry the object anyway. The two equations are and . Subtract twice the first from the second: . Then . This is a cubic Hermite segment, built from end positions and end velocities; Curves Through Points: Hermite and Catmull-Rom uses the same idea for paths. With it reduces to : smoothstep again.
// From position p0 moving at v0, to p1, arriving at rest after T seconds. u = (time since the switch) / T.
function retarget(p0: number, v0: number, p1: number, T: number) {
const D = p1 - p0 - T * v0;
const c = 3 * D + T * v0;
const d = -2 * D - T * v0;
return (u: number) => p0 + T * v0 * u + c * u * u + d * u * u * u;
}
You need at the moment of the switch. A tween can report it exactly as ; failing that, the last two frames give a good estimate, .
Notice what happens when the drawer was moving away from the new target. The Hermite keeps going for a moment, slows, turns around and comes back. That's exactly what something with momentum does, so it reads as natural rather than as a glitch.
Springs do this for free. Physically based motion (Springs: Bouncy, Critical and Sluggish) carries position and velocity as its state every frame, so a new target only changes where the spring pulls, and every handoff is automatically C¹. That's why toolkits built around gestures, which can interrupt anything at any moment, often animate with springs.
One level up: C². A C¹ handoff can still have a jump in acceleration. Two chained smoothsteps, for instance, meet at velocity , but smoothstep's acceleration at its ends is (in units of distance over duration squared), so the acceleration flips at the joint. For interface motion C¹ is plenty. For camera rigs, vehicles and robot arms, where acceleration is felt as force, designers match it too, which is what smootherstep is for: zero velocity and zero acceleration at both ends.
A common mistake. It's tempting to match the easing curves' slopes, , and call the joint smooth. But those slopes are in "progress per unit of normalized time", and each tween has its own distance and duration. What has to match is the real velocity . Ease-in quad into ease-out quad has matching slopes ( and ) every time, yet it's smooth only when both legs have the same average speed.
There are animations further down: an interrupted drawer handled both ways, the same two handoffs as velocity graphs, and a camera passing a waypoint with and without stopping.
See it
Worked examples
A camera dolly moves from m to m in s with ease-in quad, then continues from m to m with ease-out quad. How long should the second move last so the camera glides through the m mark without a jolt?
- 1
A smooth glide means the velocity arriving at m equals the velocity leaving it. Each tween's velocity is .
A drawer opens from to px over s with ease-out cubic, . At s the user taps close, and the drawer retargets to px over s with the cubic , which starts at its current position and velocity and arrives at rest. Where is it s after the tap?
- 1
First find where the drawer is at the tap. The fraction of time is , so and px.
Practice
Type your answer and check it. Solve them all to complete the lesson.
A sprite tweens from px to px in s with ease-in cubic, . How fast is it moving, in px/s, when it arrives?
A moving platform goes from m to m in s with ease-in quad, , then from m to m with ease-out cubic, . How long, in seconds, must the second move last for the velocity to be continuous at m?
A tween is interrupted while the object is moving, and the code starts a new ease-in-out tween from the object's current position to a new target. Which describes the handoff?
An object at m moving at m/s is retargeted to m over s with the cubic , where , and . Find , in meters.
A drawer opens from to px over s with ease-out cubic, . At s the user taps close, and the code naively starts a new ease-out cubic tween from the drawer's current position back to px, lasting s. By how much does the velocity change, in px/s, at the instant of the tap?
A camera moves from m to m in s, then from m to m in s, each leg using smoothstep, . The camera is at rest at the m mark, so the velocity is continuous there. By how much does the acceleration jump at that moment, in m/s²?
Two tweens are chained: ease-in quad from to px in s, then ease-out quad from px to px in s. Both easings have slope at the joint. How big is the velocity jump at the joint, in px/s?
The hardest one here. Get it, and you've got this lesson.
A drawer opens from to px over s with ease-out cubic, . At s the user taps close. The drawer retargets to px over s with a cubic that starts at its current position and velocity and arrives at rest ( is the fraction of the s that has passed since the tap). Because the drawer was still opening, it keeps opening briefly before it turns around. Find its velocity at the tap in px/s, the farthest it opens in px (to ), and how many milliseconds after the tap it turns around (to ). Enter the three numbers in that order.
Where it's used
Interfaces get interrupted constantly: a user flicks a sheet up and then back down, taps a toggle twice, or drags a card that was still settling. Toolkits handle it by retargeting from the current position and velocity (with Hermite cubics or, very often, springs), which is why a well-built drawer reverses smoothly instead of snapping. Games chain tweens into sequences for menus and cutscenes, and camera systems pass through waypoints with matched velocities so the shot never lurches. Robot arms and machine tools take it one step further and plan motion segments whose positions, velocities and accelerations all match at every joint, because a jump in acceleration is a jump in force on the motors.