Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Repel/Attracting layers and random generator

  • Repel/Attracting layers and random generator

    Posted by Dmitri Novikov on September 29, 2011 at 11:32 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 https://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.

    Dmitri Novikov replied 14 years, 7 months ago 2 Members · 2 Replies
  • 2 Replies
  • Kevin Camp

    September 29, 2011 at 4:49 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

  • Dmitri Novikov

    October 17, 2011 at 9:11 pm

    “…you could do the random positioning expression first, then convert that expression to keyframes, then apply the second expression…”
    I forget about this. Thank you. Really helpful

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy