Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Don’t run every frame

  • Don’t run every frame

    Posted by Ad Narayan on May 2, 2019 at 3:32 am

    Hey guys,

    I’m wondering if there’s a way to create a random position, but then hold that random position, from when an even triggers until it ends.

    Essentially, my event is

    a = effect("Advanced Lightning")("Core Radius");

    When a is not equal to 0, I’d like my script to calculate (and most importantly hold on to) a new position.

    a = effect("Advanced Lightning")("Core Radius");

    if (a != 0) {
    x = random(0, 3840);
    y= random(0,768);
    curPos = [x,y];
    }

    However, the way this works is that for every frame a is not 0, I’m given a new random position.
    Is there a way to trigger this the first time a changes from 0 to another value. I thought maybe a do/while would work, but that’s timing out AE’s engine.

    Any help would be appreciated. Thanks heaps!

    Lead VFX and Motion Design at Tomorrowland NZ

    Filip Vandueren replied 7 years, 2 months ago 3 Members · 3 Replies
  • 3 Replies
  • Tomas Bumbulevičius

    May 2, 2019 at 6:26 am

    Hey Ad, check this thread covered, might be helpful for your case to catch the difference: https://forums.creativecow.net/thread/227/40694

    Find out more:
    After Effects Tutorials: motion design, expressions, scripting.

  • Ad Narayan

    May 2, 2019 at 7:02 am

    You just saved my butt. I knew about seedRandom but did not know about the “timeless” second argument! Thanks heaps 🙂

    Lead VFX and Motion Design at Tomorrowland NZ

  • Filip Vandueren

    May 2, 2019 at 7:15 am

    a = effect("Advanced Lightning")("Core Radius");

    seedRandom(index,true); // "index" could be any number; ",true" makes sure the _same_ random numbers are always generated.
    fd=thisComp.frameDuration;

    p=random([0,0], [3840,720]); // even if this is called every frame, it will always return the same random number

    // we have to loop through time and check how many times "a" has become 0
    // by generating a random number for each occurrence of a=0 but was not 0 one frame ago,
    // every subsequent random() call yields a different random number.

    for (t=0; t<=time; t+=fd) {
    if (a.valueAtTime(t)==0 && a.valueAtTime(t-fd)!=0) {
    p=random([0,0], [3840,720]);
    }
    }

    p;

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy