ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Don't run every frame

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
AD Narayan
Don't run every frame
on May 2, 2019 at 3:32:57 am
Last Edited By AD Narayan on May 2, 2019 at 3:40:01 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


Return to posts index

Tomas Bumbulevičius
Re: Don't run every frame
on May 2, 2019 at 6:26:43 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.


Return to posts index

AD Narayan
Re: Don't run every frame
on May 2, 2019 at 7:02:38 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


Return to posts index


Filip Vandueren
Re: Don't run every frame
on May 2, 2019 at 7:15:31 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&lt;=time; t+=fd) {
if (a.valueAtTime(t)==0 && a.valueAtTime(t-fd)!=0) {
p=random([0,0], [3840,720]);
}
}

p;




Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]