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

I want to use a checkbox to enable/disable an expression using keyframes. How can I do this?

Explorer ,
Feb 19, 2024 Feb 19, 2024

I've animated a layer with multiple position keyframes, and now I want some of those keyframes - but not all of them - to have an overshoot expression applied. In other words, I want an expression to only affect certain specific keyframes on a layer.

I've been told that it's possible to do this using a checkbox control and keyframe the expression on or off as necessary. Unfortunately, I have no coding experience and I can't work out how to link an expression to a checkbox such that the checkbox can be used to enable or disable that expression.

Any advice gratefully received!

TOPICS
Expressions
994
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 ,
Feb 19, 2024 Feb 19, 2024

This is a keyframe overshoot expression from my site, which I've modified to skip the overshoot unless the checkbox is on at that keyframe. It may not exactly fit whatever you're using for overshoot, but hopefully it will give you an idea on how to incorporate the checkbox.

cb = effect("Checkbox Control")("Checkbox");

freq = 3;
decay = 5;

n = 0;
if (numKeys > 0){
  n = nearestKey(time).index;
  if (key(n).time > time) n--;
}
if (n > 0 && cb.valueAtTime(key(n).time)){
  t = time - key(n).time;
  amp = velocityAtTime(key(n).time - .001);
  w = freq*Math.PI*2;
  value + amp*(Math.sin(t*w)/Math.exp(decay*t)/w);
}else
  value
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
Explorer ,
Feb 20, 2024 Feb 20, 2024

Many thanks Dan, that's much appreciated!

As I say, I have no coding experience (short of writing very basic BASIC back in the 80s), and I want to learn how the Javascript syntax works. I think I can work out that your script only runs the overshoot code if the value returned by the checkbox is greater than 0, but I want to understand it properly - can you recommend any resources for beginners?

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 ,
Feb 20, 2024 Feb 20, 2024

I just used that particular overshoot expression because I had it handy. There is some discussion about how it works here:

https://www.motionscript.com/articles/bounce-and-overshoot.html#kf-overshoot

I think it's important to note that a complex expression is generally a combination of JavaScript syntax and the AE-specific extensions to the language that give you the ability to access comps, layers, properties, keyframes, etc. For the JavaScript part, I have always relied on David Flanagin's "JavaScript, The Definitive Guide" (3rd Edition for the Legacy Extendscript engine, 7th edition for the newer JavaScript engine). For the AE-specific stuff, I've always found the Expression Reference chapter in AE's help to be the best resource.

If you need help integrating the checkbox code into whatever overshoot code you're using, just post it here and we'll give you a hand.

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
LEGEND ,
Feb 20, 2024 Feb 20, 2024
LATEST

Split the layer into respective sections with and without the expressions. No need to make it more complicated than that, especially since you have no expressions knowledge.

 

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