FORUMS: list search recent posts

Repel/Attracting layers and random generator

FAQ   •   VIEW ALL
 Repel/Attracting layers and random generator on Sep 29, 2011 at 11:32:37 am

Hello!
I'm newb at expressions so I killed a lot of time tryin to achive 'repel' effect. Then I found Colin Braley article http://www.colinbraley.com/repel_expressions_tutorial.html
I've tried to use Repel (Attracting) Expression (basic version) in 3D and it's still working. Awesome!

avoidPos = thisComp.layer("Attracted Layer").position;
maxDisplacement = thisComp.layer("Controls").effect("max disp")("Slider"); //maximum amount to move the layer
minDistance = thisComp.layer("Controls").effect("min distance")("Slider"); //minimum distance to begin displacing at
//--
vec = avoidPos - position;
directionVec = normalize( vec );
distance = length( vec );
displaceAmt = ease( distance , 0 , minDistance , 0, maxDisplacement );
displacementVec = displaceAmt * directionVec;
position + displacementVec;

Exactly what I need.

But can anyone help me with combining this expression with another (Andrew Kramer's generator of random positions for the layers):

X=wiggle(0,thisComp.layer("RandomControl").effect("X")("Slider"))[0];
Y=wiggle(0,thisComp.layer("RandomControl").effect("Y")("Slider"))[1];
Z=wiggle(0,thisComp.layer("RandomControl").effect("X")("Slider"))[2];
[X,Y,Z]

So I can generate random positions for the multiple copies of the layers but they still will be respond to the movement of Attracting Layer.
One of the expressions just don't work if another pasted below.
Probaly I must edit this line "position + displacementVec" and add this random positions values to this. But I don't know how.

English is not my native language so I hope someone will understand this.
I will be very grateful for help.

 Re: Repel/Attracting layers and random generatoron Sep 29, 2011 at 4:49:22 pm

i think you just need to use your random positioning statement as the 'position' in the repelling statements...
```avoidPos = thisComp.layer("Attracted Layer").position; maxDisplacement = thisComp.layer("Controls").effect("max disp")("Slider"); //maximum amount to move the layer minDistance = thisComp.layer("Controls").effect("min distance")("Slider"); //minimum distance to begin displacing at X=wiggle(0,thisComp.layer("RandomControl").effect("X")("Slider"))[0]; Y=wiggle(0,thisComp.layer("RandomControl").effect("Y")("Slider"))[1]; Z=wiggle(0,thisComp.layer("RandomControl").effect("X")("Slider"))[2]; vec = avoidPos - [X,Y,Z]; directionVec = normalize( vec ); distance = length( vec ); displaceAmt = ease( distance , 0 , minDistance , 0, maxDisplacement ); displacementVec = displaceAmt * directionVec; position + displacementVec;```
if that still gives you problems, you could do the random positioning expression first, then convert that expression to keyframes, then apply the second expression. if you choose copy expression only for a selected layer, you can then paste it onto a all selected layers, so it would be pretty easy too.

Kevin Camp
Senior Designer
KCPQ, KMYQ & KRCW