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;
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
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
Copy link to clipboard
Copied
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.
You will get something like this:
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.