Activity › Forums › Adobe After Effects Expressions › Control Animation Between Two Keyframes with a Slider
-
Control Animation Between Two Keyframes with a Slider
Mauro Junior replied 7 years, 1 month ago 8 Members · 18 Replies
-
Dan Ebberts
August 11, 2018 at 11:58 pmYou can’t combine expressions but just putting one after the other. Only the last statement executed will have any effect. You have to blend the expressions somehow. What determines the timing of how the two sliders are supposed to interact?
Dan
-
Saara Salminen
August 12, 2018 at 3:15 pmHi Dan!
Oh, I was afraid so.
The first slider controls an animation where an object moves upwards along a curve. The animation controlled by the second slider is linear along the x-axis.
The goal is to create a controller that controls both the sliders. When the controller moves vertically, the first slider activates, and when moving the controller horizontally, the second slider is activated. It’s all part of a rig. -
Dan Ebberts
August 12, 2018 at 3:24 pmFrom that description, it sounds like it might be like this, but I’m afraid I’m missing something:
s = effect(“Slider1”)(“Slider”).value;
f = effect(“Slider2”)(“Slider”).value;
[f,s]Dan
-
Saara Salminen
August 12, 2018 at 3:52 pmNow the sliders move the object along each axis, but ignore the position animation they are supposed to control. Let me try to explain with an image:

So I’ve got a null object (called “Null_pyrstö_V”) with two sliders. The null’s position is animated, so that between the two first keyframes, the null moves in an arch. The third keyframe has the same position as the first. Between the third and the fourth keyframe the null moves in a straight line.
I’d like the first slider, called “Kaari”, to controll the animation between the two first keyframes. So that when the slider is moved, the null moves from keyframe1 to keyframe2.
The second slider, called “vaakataso”, is supposed to make the null go from the third keyframe to the fourth. So I need to find a way to combine the expressions, so that both sliders work, and I could later link them to a controller. -
Dan Ebberts
August 12, 2018 at 4:45 pmI still don’t quite get it, but maybe like this:
if (time < key(2).time){
s = effect("Slider1")("Slider");
t = linear(s,0,100,key(1).time,key(2).time)
valueAtTime(t);
}else{
f = effect("Slider2")("Slider");
linear(f,0,100,key(3).value,key(4).value);
}
Dan
-
Kalleheikki Kannisto
August 13, 2018 at 7:42 amDo you want to add the values together so that you get both motions with your controller, the horizontal motion with the x value plus the arched vertical motion with the y value combined at the same time? So as to control this animation completely with the controller, ignoring actual timeline time altogether?
If that’s the aim, you could do it like this. In this implementation the keyframes are exactly at 0,1,2 and 3 seconds and there’s a layer named “controller” with a 3D point controller on it. This adds the two motions together. 0-100 range for both x and y animations.
controller = thisComp.layer("controller").effect("3D Point Control")("3D Point");
c_x = controller[0];
c_y = controller[1];
t1 = linear(c_x,0,100,0,1);
t2 = linear(c_y,0,100,2,3);
pos1 = transform.position.valueAtTime(t1);
pos2 = transform.position.valueAtTime(t2)-transform.position.valueAtTime(2);
pos = pos1+pos2;Kalleheikki Kannisto
Senior Graphic Designer -
Saara Salminen
August 13, 2018 at 10:40 amYes, that’s exactly what I was trying to achieve! Works like a charm.
Kiitos ☺ -
Mauro Junior
April 29, 2019 at 8:52 pmHi there, is there a way to adapt this code to work with Path Objects?
s = thisComp.layer("control").effect("Slider Control")("Slider");
linear(s,0,100,key(1).value,key(2).value)
Reply to this Discussion! Login or Sign Up