Time Remapping Animation Using Markers
Advanced Expression, Dynamic, Time Based Animation
Time Remapping Animation Using Markers
This expression animates a property based on marker positions, using the time between keyframes to control the animation's duration.
This expression animates a property based on markers. It calculates the duration between the second and third keyframes and uses that to control the animation. When the current time is within the range of a marker's time and the calculated duration, it adjusts the property value. For instance, if you have markers for beats in a music track, the animation can sync to those beats dynamically.
var numMarkers = thisComp.marker.numKeys;
var animationStart = key(1).time; // Start from the second keyframe
var animationEnd = key(2).time; // End at the third keyframe
var animationDuration = animationEnd - animationStart;
var finalValue = value; // Default value if no markers are found
// Loop through the markers and calculate relative time
for (var i = 1; i <= numMarkers; i++) {
var markerTime = thisComp.marker.key(i).time;
if (time >= markerTime && time <= markerTime + animationDuration) {
var relativeTime = time - markerTime;
finalValue = thisProperty.valueAtTime(animationStart + relativeTime);
break; // Exit loop once the relevant marker is found
}
}
finalValue; // Return the calculated value
How to Use This Expression?
To use the Time Remapping Animation Using Markers Expression in After Effects, follow these steps:
Set Up Markers: Place markers on your timeline where you want the animation to respond. You can do this by pressing
*
on the numeric keypad (or right-click on the timeline and choose "Add Marker").
Apply the Expression: Select the property (e.g., position, scale, opacity) that you want to animate.
Alt-click (Windows) or Option-click (Mac) on the stopwatch icon next to the property to open the expression editor.
Paste the Expression: Copy the expression I provided earlier and paste it into the expression editor.
Adjust Keyframes: Ensure you have at least two keyframes set for the animation (the second and third keyframes in the expression), which will define the animation's start and end points.
Customize: If needed, adjust the expression to work with your specific animation setup or markers. For example, you can change the keyframe numbers (like
key(2)
andkey(3)
) based on where your keyframes are located.
Preview: Scrub through the timeline or preview the animation to see how it responds to the markers. The animation should now sync to the markers based on the defined keyframe duration.
This expression makes the animated property react dynamically to the placement of markers on your timeline, creating a flexible marker-driven animation.