Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

changing a keyframe's position in time?

Community Beginner ,
Mar 28, 2011 Mar 28, 2011

Hopefully this is clear. I want to send a person a project. It has a simple 2 keyframe animation. One is a mask property, the other a slider property on the Stroke Effect. I want a way to have the person adjust the final timing of the animation by only inputting the amount of seconds they want it to be. So for example if they want it to be 5 seconds, they would input 5 into a slider on an adjustment layer and the 2nd keyframe for the mask and the slider would adjust accordingly.

So basically I want a control for the length of the animation. If that's even possible.

TOPICS
Expressions
2.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 28, 2011 Mar 28, 2011

If the animation has exactly two keyframes, and you have layer named "control" with a slider named "duration", this should work:

dur = thisComp.layer("control").effect("duration")("Slider");
t = time;
if (numKeys >1){
  t1 = key(1).time;
  t2 = key(2).time;
  if (time > t1){
    t = ease(time,t1,t1+dur,t1,t2);
  }
}
valueAtTime(t)

Dan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 28, 2011 Mar 28, 2011

Awesome thank you so much for the help. Only issue seems to be the number I input doesn't match the final time of the animation. For example I put 1 into the slider. The animation adjusted, but ended 9 frames earlier then 1 second. I input 2 and it ended 18 frames earlier. I put 3 it's at 26 frames. At 4 its 34 frames. So the longer animation in seconds I put the amount of frames it finishes earlier by is +8ish. Any ideas?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 28, 2011 Mar 28, 2011

The expression is set up to have the slider control the duration of the animation. If you want it to control the end time, this should work:

dur = thisComp.layer("control").effect("duration")("Slider");
t = time;
if (numKeys > 1){
  t1 = key(1).time;
  t2 = key(2).time;
  if (time > t1){
    t = ease(time,t1,dur,t1,t2);
  }
}
valueAtTime(t)

Dan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 28, 2011 Mar 28, 2011

still has the same issue though the number of frames dropped by one or two.

http://www.mediafire.com/?wmdbzb8ku34ls6g

that's the reduced project file if you want to take a look at it. the distance bars layer is what has the expression. I will eventually need to put that same expression in a precomp but I might be able to just figure that out with the pick whip.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 28, 2011 Mar 28, 2011

I think the problem is that your keyframes don't line up with the start and stop of the bar animation. The expression can only tell where the keyframes are, it doesn't know that the first keyframe actually occurs 17 frames before the layer becomes visible and the 2nd keyframe occurs some time after the bar is fully extended. So I think the expression is doing what it should, relative to the animation of the mask -- it's just that it doesn't correspond to the timing you're expecting as fas a the anmiation of the bar itself.

Dan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 28, 2011 Mar 28, 2011

so I fixed the keyframe issue you mentioned and it still had that offset. So I changed the ease to linear. and now the number of offset frames seemed to be the same number of the input. so I messed around until i got this:

dur = thisComp.layer("control").effect("duration")("Slider");
t = time;

// .03333 = 1 frame per second at 29.97fps

off = dur*.03333;
if (numKeys > 1){
  t1 = key(1).time;
  t2 = key(2).time;
  if (time > t1){
    t = linear(time, t1, dur, t1, t2-off);
    }
}
valueAtTime(t)

seems to be working

thanks a ton for your help!!!!!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 28, 2011 Mar 28, 2011
LATEST

Hmmm.... All I have to do is change the bar animation to start at the first keyframe and end at the second, and it works perfectly for me. In any case, I'm glad you got it working.

Dan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines