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

Make an expression run every few seconds

New Here ,
Jul 16, 2021 Jul 16, 2021

Copy link to clipboard

Copied

I am trying to create a jittering effect for an object in after effects.  To do this I used an expression to generate random values between specific cordinates for the position.  The problem is this code is executing every single frame so it looks terrible.  To avoid this I tried using if/then statements using time.  However, I keep getting errors stating that time is an undefined value.  If there is a way to fix my code or a simpler way to accomplish the same goal please let me know.

 

Here is my code:

if(time == 0){
     p = [960,540];
}else{
     if((time % 2) == 0){
          p = random([950,530],[970,560]);
     }
}
p;

TOPICS
Error or problem , Expressions , FAQ , Scripting

Views

1.5K

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
LEGEND ,
Jul 16, 2021 Jul 16, 2021

Copy link to clipboard

Copied

The code wouldn't do what you want, anyway, so it's a moot point, but you have an extraneaous curly bracket that may throw things of. Anyway, if you really want to switch positions every two seconds, all it needs is to control the random seed:

 

seedRandom(Math.floor(time/2))

 

X=random(950,970);

Y=random(530,560);

 

[X,Y]

 

Mylenium

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
Community Expert ,
Jul 17, 2021 Jul 17, 2021

Copy link to clipboard

Copied

If you add this at the beginning of your expression, it will only be executed once per second:

posterizeTime(1);

 

If you do

posterizeTime(2);

it will be executed twice per second

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects

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
Community Expert ,
Jul 17, 2021 Jul 17, 2021

Copy link to clipboard

Copied

LATEST

Halfway between 950 and 970 is 960 and the range is 10. 

Halfway between 530 and 560 is 545 and the range is 15.

 

If the motion is random, it is highly unlikely that you would notice the 2.5-pixel difference between X and Y so just positioning the layer at 960, 545, and adding wiggle(4, 12.5) would give you a jitter that is close to the right range. If you want to make the movements sharper Pre-compose the layer moving all attributes, open the Composition settings of the new comp and change the frame rate to 6fps, click on the advanced tab, and set the comp to preserve frame rate when nested.

setup.png

You will get something like this:

wiggle.gif

That's the simplest way I know of. 

 

If you want the precise range for X and Y, separate dimensions. There is no need to monkey with time at all unless you want random sections with no movement. 

 

 

 

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