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

Help in animating value between keyframes using expression

Community Beginner ,
Jan 09, 2023 Jan 09, 2023

I am working on lipsync animation using a slider. It was tedious, but I thought of a way to ease the process but I have no idea how.

I want an expression that adds a transition between two same keyframes. The slider I use has 0-100 value btw. I want an expression that works like below

  • if a keyframe and the next one has a same value, the value will decrease by 0.5 between them
  • but if the value of the two keyframes is greater than 50, it will increase by 0.5 instead.

 

I'm a complete beginner when it comes to expressions. I hope someone will help. Thank you very much in advance.

 

TOPICS
Expressions
579
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

correct answers 1 Correct answer

Community Expert , Jan 10, 2023 Jan 10, 2023

More like this maybe:

val = value;
if (numKeys > 1){
  if (time >= key(1).time && time < key(numKeys).time){
    n = nearestKey(time).index;
    if (time < key(n).time) n--;
    if (n > 0){
      if (key(n).value == key(n+1).value){
        mid = (key(n).time + key(n+1).time)/2;
        v1 = key(n).value;
        v2 = v1 - .5;
        if (time < mid)
          val = linear(time,key(n).time,mid,v1,v2)
        else
          val = linear(time,mid,key(n+1).time,v2,v1);
      }
    }
  }
}
val
Translate
LEGEND ,
Jan 09, 2023 Jan 09, 2023

Refer to this post as an example for some of the necessary code:

 

https://community.adobe.com/t5/after-effects-discussions/modifying-value-at-a-specific-keyframe-with...

 

The methodology is pretty much the same, you just need to modify the conditionals. Also check this:

 

http://www.motionscript.com/design-guide/audio-trigger.html

 

Mylenium

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 ,
Jan 09, 2023 Jan 09, 2023

I somehow get how the solution there works. But with my limited understanding, I assume that those only work with 2 keyframes. What I'd like to do is make an expression to work on all keyframes and only with the same value.

I think I know how to do the right "if statement" when it comes to value. But I don't have an idea how to do one where I select only the keyframes I want among all the keyframes.

 

Also thanks for the audio trigger link, it looks helpful.

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 ,
Jan 09, 2023 Jan 09, 2023

If you apply an expression, it has to supply a value for each frame, not just at the keyframes. So it's important to specify what it needs to do in every situation. Maybe a marked-up screen shot of what you're trying to do would 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 Beginner ,
Jan 09, 2023 Jan 09, 2023

StevenKent27869994kodo_1-1673335655116.png

In this image, the two keyframes have the same value of 0.77 and my I idea is decrease the value by 0.5 and make it 0.22 on the part between them. Basically, just like adding another keyframe in between. I am looking for expressions that can do this on the rest of keyframes with the same value.

Sorry, I hope I explained it well.

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 ,
Jan 09, 2023 Jan 09, 2023

I think this is what you're describing, but I'm guessing it's not what you want:

val = value;
if (numKeys > 1){
  if (time >= key(1).time && time < key(numKeys).time){
    n = nearestKey(time).index;
    if (time < key(n).time) n--;
    if (n > 0){
      if (key(n).value == key(n+1).value){
        val = key(n).value - .5;
      }
    }
  }
}
val
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 ,
Jan 10, 2023 Jan 10, 2023

Tried this, but the decrease in value was applied from first keyframe instead in between of the two.

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 ,
Jan 10, 2023 Jan 10, 2023

More like this maybe:

val = value;
if (numKeys > 1){
  if (time >= key(1).time && time < key(numKeys).time){
    n = nearestKey(time).index;
    if (time < key(n).time) n--;
    if (n > 0){
      if (key(n).value == key(n+1).value){
        mid = (key(n).time + key(n+1).time)/2;
        v1 = key(n).value;
        v2 = v1 - .5;
        if (time < mid)
          val = linear(time,key(n).time,mid,v1,v2)
        else
          val = linear(time,mid,key(n+1).time,v2,v1);
      }
    }
  }
}
val
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 ,
Jan 10, 2023 Jan 10, 2023
LATEST

Thank you so much Dan! This works.

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