Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Switching between 2 position leaders with a slider

  • Switching between 2 position leaders with a slider

    Posted by Thomas Ginelli on January 25, 2012 at 9:42 am

    Hello!

    I’m trying to set up a slider that would control how much a layer should follow the movement of 2 separate “leader” layers.

    When the slider is at 0, it should follow the movement of layer A, and at 100% it should follow the movement of layer B. That would be perfect, but if it is easier to set up the expression with 2 sliders I’m ok with that.

    What I got so far is an expression that works, only that it follows the POSITION while I need the MOVEMENT to be captured. So now I can set up a slider % and then the starting pos of my target layer, but can’t animate the slider cause it just moves the layer closer or away from the starting point.

    So my question is:
    how can I track the movement of a layer? must I write some expression that checks for a layer’s pos changes between frames, and start from there?

    Yaneev Topyol replied 14 years, 3 months ago 4 Members · 4 Replies
  • 4 Replies
  • Kevin Camp

    January 25, 2012 at 4:32 pm

    try this:

    a = effect("Slider Control")("Slider");
    p1 = thisComp.layer("Leader1").transform.position;
    p2 = thisComp.layer("Leader2").transform.position;

    dX = p1[0]-p2[0];
    dY = p1[1]-p2[1];

    p1-([dX,dY]*a/100)

    Kevin Camp
    Senior Designer
    KCPQ, KMYQ & KRCW

  • Kevin Camp

    January 25, 2012 at 4:43 pm

    slightly modified (clamped values for the percentage to be between 0-100, and simplified the distance calc.):

    a = clamp(effect("Slider Control")("Slider"),0,100);
    p1 = thisComp.layer("Leader1").transform.position;
    p2 = thisComp.layer("Leader2").transform.position;

    d = sub(p1,p2);

    p1-(d*a/100)

    Kevin Camp
    Senior Designer
    KCPQ, KMYQ & KRCW

  • Dan Ebberts

    January 25, 2012 at 7:41 pm

    I think you’re looking for something like this:


    s = effect("Slider Control")("Slider");
    accum = 0;
    for(f = timeToFrames(inPoint); f <= timeToFrames(time); f++){
    t = framesToTime(f);
    vA = thisComp.layer("Layer A").transform.position.velocityAtTime(t);
    vB = thisComp.layer("Layer B").transform.position.velocityAtTime(t);
    v = linear(s.valueAtTime(t),0,100,vA,vB);
    accum += v*thisComp.frameDuration;
    }
    value + accum

    Dan

  • Yaneev Topyol

    January 30, 2012 at 1:43 pm

    Hi Thomas

    here’s what i use for this purpose, and it works the same for both 2D and 3D.

    i find it very easy to read and manipulate.
    for me this has worked in complicated settings, such as rearranging multiple layers across different comps (fun!!).

    best,
    y

    lead1 = thisComp.layer("leader1").transform.position;
    lead2 = thisComp.layer("leader2").transform.position;
    select = effect("Slider Control")("Slider");

    linear(select, 0, 100, lead1, lead2)

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