Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Expression for circles following a curved path?

  • Expression for circles following a curved path?

    Posted by Mike on November 9, 2005 at 9:17 pm

    I’ve searched the COW archives and found a lot of info on this subject, but nothing that is a total solution to what I’m trying to do. I have a line of 7 circles with an even amount of space in between them. I want to be able to move the line in a “snake-like” manner across the screen and have the cirlces all follow along the curve AND maintain their even relationship to one another. I’ve gotten close with this:

    offset = 1;//Delay in seconds
    thisComp.layer(index – 1).position.valueAtTime(time – offset)

    But in the end this doesn’t work for me because the followers all come together with the leader at the beginning and end of the keyframes. I need to keep the circles evenly spaced with each other as they move along the path. Any help is greatly appreciated!

    Thanks,
    Mike

    Mike replied 19 years, 5 months ago 3 Members · 4 Replies
  • 4 Replies
  • Colin Braley

    November 10, 2005 at 12:39 am

    Michael –
    I’ve got an expression that seems to work pretty well, but I’m not sure if it is exactly what you are looking for. Just keyframe the position of the first layer and then apply this expression to the position property of all the other circles (they must be directly below the other circles in the timeline because the expression relies on layer indicies). Well, here is the expression:

    //Begin expression
    offSet = 500;//In pixels
    //—–
    frame = timeToFrames(time);
    prevPos = thisComp.layer(index – 1).position;
    var finalPos;
    //–
    function getPrevPosAtTime( f )//Time in frames is passed to the function
    {
    return prevPos.valueAtTime( framesToTime( f ));
    }
    //–
    var bestFrame = 0;
    //–
    for(i = 0; i < frame; i++) { curr = length(getPrevPosAtTime( i ), prevPos); currError = Math.abs(curr - offSet); oldCurr = length(getPrevPosAtTime( bestFrame), prevPos); oldError = Math.abs(oldCurr - offSet); if(currError < oldError) bestFrame = i; } //-- getPrevPosAtTime( bestFrame ) //End expression I think that expression should get you headed in the right direction. If you have any trouble with it post again. ~Colin

  • Dan Ebberts

    November 10, 2005 at 12:40 am

    Check out the last three examples on this page:

    https://www.motionscript.com/mastering-expressions/follow-the-leader.html

    Dan

  • Colin Braley

    November 10, 2005 at 12:51 am

    Dan-
    I probably should have checked your site before spending the last 15 minutes trying to write that expression 🙂 In mine the distance between the two layers isn’t always perfect, sometimes its off by a few pixels.

    ~Colin

  • Mike

    November 10, 2005 at 2:25 pm

    Dan and Colin – thanks so much! I will give it a try.

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