FORUMS: list search recent posts

sliders to control time between keyframes

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Mike Throck
sliders to control time between keyframes
on Jun 11, 2011 at 4:05:45 am

I have an object that moves from one place to another, holds there and then moves to another location and scales up.

I'd like to control the amount of time it holds with an expression slider, and not have to move any of the scale keyframes.

I'm not very experienced with expressions, so any help is appreciated.


Return to posts index

Dan Ebberts
Re: sliders to control time between keyframes
on Jun 11, 2011 at 2:31:58 pm

I'm not sure if this is exactly what you're after, but you would apply this expression to both the position and scale properties. It's set up to substitute the slider value for the time between position keyframes 2 and 3 (change the values of k1 and k2 if it should be a different pair):


holdTime = effect("Slider Control")("Slider");
k1 = 2; // 1st hold keyframe
k2 = 3; // 2nd hold keyframe
p = transform.position;
t1 = p.key(k1).time;
t2 = t1 + holdTime;
if (time < t1)
t = time
else if (time < t2)
t = linear(time,t1,t2,t1,p.key(k2).time)
else
t = p.key(k2).time + (time - t2);
valueAtTime(t)


Dan



Return to posts index

Mike Throck
Re: sliders to control time between keyframes
on Jun 11, 2011 at 6:52:17 pm

This is exactly what I needed, thank you much! It even still recognizes the easy ease.


Return to posts index


Mike Throck
Re: sliders to control time between keyframes
on Jun 11, 2011 at 9:50:24 pm

Your answer was so helpful, I was hoping you could help me add one more element.

As the object scales up I want it's parent object's ( a null) Y position to animate in time as well. The expression you already gave me would do this, but I would like the value of the Y position to be controlled by a slider as well.

How do I get the Null's second keyframe to be driven by a slider and still work with the other expression.

you are the man, of course.


Return to posts index

Dan Ebberts
Re: sliders to control time between keyframes
on Jun 11, 2011 at 10:31:26 pm

OK, you lost me. I thougt I was with you until you mentioned the null's 2nd keyframe. Are you just talking about adding the value of the slider to the null's y position, or is this another timing-control slider?


Dan



Return to posts index

Mike Throck
Re: sliders to control time between keyframes
on Jun 11, 2011 at 10:37:35 pm

I guess what I'm after is this:

I'd like the anchor point, scale and posY to be controlled by sliders but I'd like to just enter a value and not have to adjust keyframes.

Much like the time between them is controlled by a slider where I enter a number. Is it possible to have a slider determine one keyframes value but not the other?


Return to posts index


Dan Ebberts
Re: sliders to control time between keyframes
on Jun 12, 2011 at 12:01:24 am

So you want to be able to substitute a value at a particular keyframe, is that correct? If so, which one, the last one?

Dan



Return to posts index

Mike Throck
Re: sliders to control time between keyframes
on Jun 12, 2011 at 12:24:54 am

Yes, and the second of the 2 keyframes.

I basically want to be able to change the value of a keyframe using a slider control, without having to scrub to that point in time.


Return to posts index

Dan Ebberts
Re: sliders to control time between keyframes
on Jun 12, 2011 at 12:59:55 am

The only way I can think of would lose any easing or deviation you had built into the keyframes. It would go straight from the value at keyframe 1 to the slider value, using the timing generated with the previous expression. Is it still worth doing?

Dan



Return to posts index


Mike Throck
Re: sliders to control time between keyframes
on Jun 12, 2011 at 1:03:39 am

I guess not, the easing is important.

I'm building a template for people who don't know after effects very well and I wanted to make it as easy to use as possible.

Thanks for all your help, especially on a Saturday!


Return to posts index

Lukasz Lindell
Re: sliders to control time between keyframes
on Jun 15, 2011 at 1:23:54 pm

holdTime = effect("Slider Control")("Slider");
k1 = 2; // 1st hold keyframe
k2 = 3; // 2nd hold keyframe
p = transform.position;
t1 = p.key(k1).time;
t2 = t1 + holdTime;
if (time < t1)
t = time
else if (time < t2)
t = linear(time,t1,t2,t1,p.key(k2).time)
else
t = p.key(k2).time + (time - t2);
valueAtTime(t)


Hijacking this thread a litte, but this was exactly what I was after. I tried to add more keyframes to hold, up to 10. I started out with adding to the:

k1 = 2; // 1st hold keyframe
k2 = 3; // 2nd hold keyframe


and created:

k3 = 4; // 3rd hold keyframe

and so on, up to k10. Then I added:

t3 = t2 + holdTime;
t4 = t3 + holdTime;


Guess I'm doing fine so far, but here my little skills ended. How do I keep on adding to this expression? This part really messed it up for me:

if (time < t1)
t = time
else if (time < t2)
t = linear(time,t1,t2,t1,p.key(k2).time)
else
t = p.key(k2).time + (time - t2);


Dont know where to go from here though...


Return to posts index

Dan Ebberts
Re: sliders to control time between keyframes
on Jun 15, 2011 at 3:25:21 pm

I guess it would be like this:


holdTime = effect("Slider Control")("Slider");
k1 = 2; // 1st hold keyframe
k2 = 3; // 2nd hold keyframe
k3 = 4;
k4 = 5;
k5 = 6;
k6 = 7;
k7 = 8;
k8 = 9;
k9 = 10;
k10 = 11;
p = transform.position;
t1 = p.key(k1).time;
t2 = t1 + holdTime;
t3 = t2 + holdTime;
t4 = t3 + holdTime;
t5 = t4 + holdTime;
t6 = t5 + holdTime;
t7 = t6 + holdTime;
t8 = t7 + holdTime;
t9 = t8 + holdTime;
t10 = t9 + holdTime;
if (time < t1)
t = time
else if (time < t2)
t = linear(time,t1,t2,t1,p.key(k2).time)
else if (time < t3)
t = linear(time,t2,t3,t2,p.key(k3).time)
else if (time < t4)
t = linear(time,t3,t4,t3,p.key(k4).time)
else if (time < t5)
t = linear(time,t4,t5,t4,p.key(k5).time)
else if (time < t6)
t = linear(time,t5,t6,t5,p.key(k6).time)
else if (time < t7)
t = linear(time,t6,t7,t6,p.key(k7).time)
else if (time < t8)
t = linear(time,t7,t8,t7,p.key(k8).time)
else if (time < t9)
t = linear(time,t8,t9,t8,p.key(k9).time)
else if (time < t10)
t = linear(time,t9,t10,t9,p.key(k10).time)
else
t = p.key(k10).time + (time - t10);
valueAtTime(t)


I haven't tested this and there are probably better ways to code it, but hopefully it will do what you want.


Dan



Return to posts index


Lukasz Lindell
Re: sliders to control time between keyframes
on Jun 17, 2011 at 10:38:36 am

Thanks a lot Dan, that will work!


Return to posts index

Greg Antisdel
Re: sliders to control time between keyframes
on Nov 3, 2014 at 8:53:08 pm

Hi Dan,

This expression is awesome! I was wondering if we could specify a min and max range for the slider?

For example, if the value entered by the slider is a negative number, the animation will continue normally up until the second keyframe and then the next frame it will snap to the fourth keyframe. If the value entered by the slider is longer than the animation, the third and fourth keyframes will never be reached.

I was thinking something along the lines of

if (holdTime<3);
t=3
else if (holdTIme>28);
t=28
else

But I am obviously missing something.

Any help would be greatly appreciated.

Thanks

Greg


Return to posts index

Greg Antisdel
Re: sliders to control time between keyframes
on Nov 4, 2014 at 3:34:33 pm

I just figured out that I can set the range on the slider itself, so no need to worry about the code.


Return to posts index


Hung Nguyen Dac
Re: sliders to control time between keyframes
on Dec 25, 2014 at 10:13:22 am

Hi Dan. Your code worked with "tranform", but i wanna use this code for Shape "path\shape1\path-stroke-fill-tranform".
I was changed "p = transform.position; => p = contents.shape 1.path;"
But it doesn't work. Please help me.


Return to posts index

Dan Ebberts
Re: sliders to control time between keyframes
on Dec 25, 2014 at 6:37:21 pm

Which property has the keyframes? Which property has the expression? Are you getting an error message? If so, what is it?

Dan



Return to posts index

Hung Nguyen Dac
Re: sliders to control time between keyframes
on Dec 26, 2014 at 2:53:41 am
Last Edited By Hung Nguyen Dac on Dec 28, 2014 at 12:58:32 am

I have 2 problems:
1.I want to use your code with other properties. Ex. Shape and Mask (like this picture), but it always show error occurred at line 4. I think I was the wrong path.
2. I had 12 keyframes.
- If I start with "k1=2", after I'm increased slider, then keyframes: 3,4,5,6,7,8,9,10,11,12 also increase value of the slider. I only want it to affect keyframes:11, k12
- If I start with "k1=10" then the time of motion begins at keyframe 10 while I want it to start at keyframe 2. I don't want it affect to keyframe 3->10



Return to posts index

Dan Ebberts
Re: sliders to control time between keyframes
on Dec 26, 2014 at 4:41:39 am

Try changing the 4th line to this:

p = thisProperty;

and see if that eliminates the error. I'm not sure what the second part of your question is asking though.

Dan



Return to posts index

Hung Nguyen Dac
Re: sliders to control time between keyframes
on Dec 28, 2014 at 10:52:01 am
Last Edited By Hung Nguyen Dac on Dec 28, 2014 at 1:24:05 pm

Thank Dan! I was corrected 2 problems.
1. I used "p=thisProperty;" and it worked with Shape and Mask.
2. I just change "t2 = t1 + holdTime;" => "t2 = t1 + holdTime - (second);"

I have a new problem. I use this code. It can scale layer by slider, but it doesn't work with keyframes in this layer. How to make it correct?

x=100; //100% Comp
y=100; //100% Comp
t=thisComp.layer("Scale").effect("Scale Y")("Slider");
if (t>=y)
[x,y]
else
[x,t]


Return to posts index

Dan Ebberts
Re: sliders to control time between keyframes
on Dec 28, 2014 at 5:43:43 pm

It's hard to say for sure, but you might be looking for something like this:

t=thisComp.layer("Scale").effect("Scale Y")("Slider");
[value[0],value[1]*t/100]


Dan



Return to posts index

Hung NguyenDac
Re: sliders to control time between keyframes
on Jan 1, 2015 at 5:39:42 am

It's worked. New Year has come, allow me to congratulate you and your family all my best wishes for perfect health and lasting prosperity in the New Year :)


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]