Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Roving objects position?

  • Roving objects position?

    Posted by Erin Patrick on November 29, 2006 at 5:14 pm

    Ok, this seems sort of hard to explain, but here goes:
    Imagine 4 dots, placed directly on top of eachother. Now imagine moving dot A to the right, as dots B and C move in proportion inbetween the other two dots (think roving keyframes). Like they were attached to a rubber band maybe.
    I want to “rove” the position of some object based on the position of two other points. Is this possible? And easy enough for my puny brain to omprehend?
    Thanks in advance for any advice!!

    Mike Clasby replied 19 years, 8 months ago 3 Members · 7 Replies
  • 7 Replies
  • Dan Ebberts

    November 29, 2006 at 5:55 pm

    If “Layer A” and “Layer D” are the end points, one in-between layer could have a Position expression like this:

    A = thisComp.layer(“Layer A”).position;
    D = thisComp.layer(“Layer D”).position;
    A + (D – A)/3;

    And the other one like this:

    A = thisComp.layer(“Layer A”).position;
    D = thisComp.layer(“Layer D”).position;
    A + (D – A)*2/3;

    There are ways to automate it based on layer index if you have a bunch of layers, but this should get you started.

    Dan

  • Erin Patrick

    November 29, 2006 at 6:03 pm

    Ok, cool! I didn’t know it was so easy. I’d love to here the “automate it based on layer index if you have a bunch of layers” bit.
    Thanks again.

  • Dan Ebberts

    November 29, 2006 at 6:12 pm

    If you have a bunch of layers, you could apply this expression to all the layers, then just drag the first one or last one around and the others should spread out in between:

    if (thisComp.numLayers > 1){
    P1 = thisComp.layer(1).position;
    P2 = thisComp.layer(thisComp.numLayers).position;
    P1 + (P2 – P1) * (index – 1) / (thisComp.numLayers – 1)
    }else{
    value
    }

    Dan

  • Mike Clasby

    November 29, 2006 at 10:37 pm

    Dan, I love that expression (second one), but I can’t get it to play nicely with others. When I add any other layers to the comp, they don’t act the same (I wanted to add an audio layer and Convert audio to keyframes to drive one of the end layers with music).

    I tried hacking it, like line 3 to:

    P2 = thisComp.layer(thisComp.numLayers-2).position;

    but no luck. Any insights?

  • Dan Ebberts

    November 29, 2006 at 10:47 pm

    Mike, this should fix it. Just set “layersToSkip” the number of layers not participating in the chain and make sure those layers are at the bottom of the layer stack.

    layersToSkip = 2;

    if (thisComp.numLayers > 1 + layersToSkip){
    P1 = thisComp.layer(1).position;
    P2 = thisComp.layer(thisComp.numLayers – layersToSkip).position;
    P1 + (P2 – P1) * (index – 1) / (thisComp.numLayers – 1 – layersToSkip)
    }else{
    value
    }

    Dan

  • Mike Clasby

    November 29, 2006 at 11:00 pm

    Thanks mucho.

  • Mike Clasby

    November 29, 2006 at 11:29 pm

    Works a charm, but to get audio to drive the end layer, I changed it’s expression to this:

    layersToSkip = 2;
    temp = thisComp.layer(“Audio Amplitude”).effect(“Both Channels”)(“Slider”)*10
    if (thisComp.numLayers > 1 + layersToSkip){
    P1 = thisComp.layer(1).position;
    P2 = thisComp.layer(thisComp.numLayers – layersToSkip).position + [temp, temp];
    P1 + (P2 – P1) * (index – 1) / (thisComp.numLayers – 1 – layersToSkip)
    }else{
    value
    }

    Line 2 and the P2 line are hacked.

    Thanks again.

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