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

Fire action on every keyframe

Explorer ,
May 03, 2019 May 03, 2019

Copy link to clipboard

Copied

I want drive change of effect property on every keyframe: it would change its value from 0 to 1 and vice versa (basically on & off).

So far I have this expression for the effect "Dust & Scratches" sitting on its "Threshold" property:

var v = 1;

var n = timeRemap.numKeys;

if (n > 0){

    if(time < timeRemap.nearestKey(time).time){

        if(v == 0){

            v = 1;

        }else{

            v = 0

        }

    }

}

v

Problem is I would like to be able fire the change exactly on every new keyframe but I am not able to get there, this is the closest but of course it changes the value "erratically" once it reaches middle point between two frames.

I tried also this but to no success too as the variables kfA/kfB are initialized with every frame 😞

var kfA = 1;

var kfB = 2;

var v = 1;

var n = timeRemap.numKeys;

if (n > 0){

    if(time >= timeRemap.key(kfA).time && time < timeRemap.key(kfB).time){

        if(v == 0){

            v = 1;

        }else{

            v = 0

        }

    }

    if(time == timeRemap.key(kfB).time){

        kfA++;

        kfB++;

    }

}

v

TOPICS
Expressions

Views

543

Translate

Translate

Report

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

Enthusiast , May 03, 2019 May 03, 2019

I posted this in your other thread but as suggested, posting it here too. Apply it to the Threshold property of the Dust & Scratches effect.

Glad to hear it works!

a = timeRemap;

nearestKey = a.nearestKey(time).index;

if (time < a.key(nearestKey).time) nearestKey --;

if (nearestKey/2 != Math.round(nearestKey/2)) 0;

else 255;

Translation for the above would be:

grab the timeRemap property for this layer

find the index of the nearest remap keyframe at the current time (expressions are recalculated on each

...

Votes

Translate

Translate
Enthusiast ,
May 03, 2019 May 03, 2019

Copy link to clipboard

Copied

I posted this in your other thread but as suggested, posting it here too. Apply it to the Threshold property of the Dust & Scratches effect.

Glad to hear it works!

a = timeRemap;

nearestKey = a.nearestKey(time).index;

if (time < a.key(nearestKey).time) nearestKey --;

if (nearestKey/2 != Math.round(nearestKey/2)) 0;

else 255;

Translation for the above would be:

grab the timeRemap property for this layer

find the index of the nearest remap keyframe at the current time (expressions are recalculated on each individual frame)

if the current time is earlier than the nearest keyframe, reduce 'nearestKey' by 1 so we're always considering the keyframe before the current time.

if keyframe is an odd value (i.e. if value divided by 2 doesn't equal the same result rounded down) make the value 0, otherwise make it 255.

Votes

Translate

Translate

Report

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 ,
May 03, 2019 May 03, 2019

Copy link to clipboard

Copied

LATEST

Thank you once again!

Votes

Translate

Translate

Report

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