FORUMS: list search recent posts

Random position from index AND looping wiggle

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Bryan Woods
Random position from index AND looping wiggle
on Aug 12, 2016 at 5:11:43 pm

Ok, I'm getting a little in the weeds here, and could use a second pair of eyes on this code.

I've set up a layer to randomly position its self in 3D based on its index, but now I also need to make sure every layer has a subtle bit of random movement, that can be looped. At the moment my code mostly works, however looping is an issue. The position seems to pop to a certain place, and then run, but then when it reaches the end of the loop, pops to a different position.

seedRandom(index,true);
s = thisComp.layer("Seed").effect("Seed")("Slider");

//random position setup. The mods allow me to adjust spread in x,y,z with sliders
xMod = thisComp.layer("Seed").effect("X_Mod")("Slider");
yMod = thisComp.layer("Seed").effect("Y_Mod")("Slider");
zMod = thisComp.layer("Seed").effect("Z_Mod")("Slider");
a = [-s*xMod, -s*yMod, -s*zMod];
b = [s, s, s];

//wiggle setup
wigFreq = thisComp.layer("Seed").effect("WigFreq")("Slider");
wigAmp = thisComp.layer("Seed").effect("WigAmp")("Slider");
loopTime = 2;
t = time % loopTime;

wiggleX1 = wiggle(wigFreq, wigAmp, t);
wiggleX2 = wiggle(wigFreq, wigAmp, t - loopTime);
wiggleY1 = wiggle(wigFreq, wigAmp, t);
wiggleY2 = wiggle(wigFreq, wigAmp, t - loopTime);
wiggleZ1 = wiggle(wigFreq, wigAmp, t);
wiggleZ2 = wiggle(wigFreq, wigAmp, t - loopTime);
X=linear(t, 0, loopTime, wiggleX1, wiggleX2)[0];
Y=linear(t, 0, loopTime, wiggleY1, wiggleY2)[1];
Z=linear(t, 0, loopTime, wiggleZ1, wiggleZ2)[2];

position.value + random(a,b)+[X,Y,Z]; //this might be the culprit, as I don't think I'm combining these different variables properly


Return to posts index

Bryan Woods
Re: Random position from index AND looping wiggle
on Aug 12, 2016 at 5:20:24 pm

Oh, wait! I think I got it. Re-reading Dan's write-up on looping wiggle expressions, looks like I was forgetting the default values for the third and fourth spots in the wiggle() expression (1, 0.5). Adding these in make my code work! I've included the code below for anyone else who may want to use a randomly positioning layer in 3D space with random looping wiggle position

seedRandom(index,true);
s = thisComp.layer("Seed").effect("Seed")("Slider");

xMod = thisComp.layer("Seed").effect("X_Mod")("Slider");
yMod = thisComp.layer("Seed").effect("Y_Mod")("Slider");
zMod = thisComp.layer("Seed").effect("Z_Mod")("Slider");

a = [-s*xMod, -s*yMod, -s*zMod];
b = [s, s, s];

wigFreq = thisComp.layer("Seed").effect("WigFreq")("Slider");
wigAmp = thisComp.layer("Seed").effect("WigAmp")("Slider");
loopTime = 2;
t = time % loopTime;

wiggleX1 = wiggle(wigFreq, wigAmp, 1, 0.5, t);
wiggleX2 = wiggle(wigFreq, wigAmp, 1, 0.5, t - loopTime);
wiggleY1 = wiggle(wigFreq, wigAmp, 1, 0.5, t);
wiggleY2 = wiggle(wigFreq, wigAmp, 1, 0.5, t - loopTime);
wiggleZ1 = wiggle(wigFreq, wigAmp, 1, 0.5, t);
wiggleZ2 = wiggle(wigFreq, wigAmp, 1, 0.5, t - loopTime);
X=linear(t, 0, loopTime, wiggleX1, wiggleX2)[0];
Y=linear(t, 0, loopTime, wiggleY1, wiggleY2)[1];
Z=linear(t, 0, loopTime, wiggleZ1, wiggleZ2)[2];

position.value + random(a,b)+[X,Y,Z];


Return to posts index

Bryan Woods
Re: Random position from index AND looping wiggle
on Aug 12, 2016 at 5:42:23 pm

Ok, actually, I need a little more help. I need to be able to apply this expression to each layer thats already in a good position. The wiggle just needs to pick up from where the layer is, and I'm not getting that to work. I think this comes down to how I'm adding everything up on the last line.

Essentially, I like the value generated from position.value+random(a,b). Now I want to initiate the wiggle from that value.


Return to posts index


Kevin Camp
Re: Random position from index AND looping wiggle
on Aug 12, 2016 at 8:51:08 pm
Last Edited By Kevin Camp on Aug 12, 2016 at 9:07:09 pm

this will generate a unique random position for each layer and then 'wiggle' it around that random value, but still allow you to manually adjust the random position (i.e., use the position property value). it generates the random position from a volume defined by the x, y, z variables for the back-lower-right corner and then it's inverse for the front-upper-left corner of a cube. you can link those variable to your sliders. if needed, you could set up separate sliders to define the front-upper-left corner rathe than simply using the inverse. the rest of the code is from dan's looping wiggle expression -- which I think you are familiar with ;)
seedRandom(index,true);
x = 300;
y = 300;
z = 300;
p = random(-[x,y,z],[x,y,z])
freq = 1;
amp = 110;
loopTime = 3;
t = time % loopTime;
wiggle1 = wiggle(freq, amp, 1, 0.5, t);
wiggle2 = wiggle(freq, amp, 1, 0.5, t - loopTime);
w = linear(t, 0, loopTime, wiggle1, wiggle2);
normalize(value) + p + w


----- edit ----

scratch the 'normalize()' from the last line... completely unnecessary. should be just: p + w

Kevin Camp
Art Director
KCPQ, KZJO & KRCW


Return to posts index

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