Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Need assistance with follow expression

  • Need assistance with follow expression

    Posted by Nate Biehl on July 25, 2012 at 3:38 pm

    Hi folks,

    I am animating a centipede to move along a path. The centipede consists of a head precomp, 8 body segments, and a tail.

    I have animated the head along a path. To get the body segments to follow the head segment, I used the expression below (copied from an old post on this forum) on the position property of each body segment. This worked beautifully.

    For the next step, I need this centipede to stop moving and then start again. Right now when the head stops, all the body segments converge on the same position as the head. Is there any way to freeze that expression so the segments stay in position? I know I could time remap the entire composition to freeze it, but then motion blur becomes a problem.

    I tried containing this expression inside a stop time expression, but each segment just reverted to it’s original position, and then all the segments did because of the index-1 code. Is there a way to use the ELSE command to tell the body segments to maintain distance when the head stops moving?

    I need to figure out a solution by today, so any ideas are appreciated. Thanks!

    thisComp.layer(index-1).position.value_at_time(time-thisComp.layer("centipede conrol").effect("Slider Control")("Slider"))

    Motion Graphics Designer
    Warm Springs Productions
    Missoula, Montana

    Nate Biehl replied 13 years, 9 months ago 2 Members · 8 Replies
  • 8 Replies
  • Dan Ebberts

    July 25, 2012 at 4:19 pm

    I think the 6th expression in this article is what you want (the A Completely Different Approach section):

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

    Dan

  • Nate Biehl

    July 25, 2012 at 4:37 pm

    Hi Dan,
    Thanks for your response! I am working with 2d layers. Will this technique work on 2d layers, or do I need to change them to 3d?
    Thanks again.

    Motion Graphics Designer
    Warm Springs Productions
    Missoula, Montana

  • Nate Biehl

    July 25, 2012 at 4:48 pm

    Actually, Dan, I just remembered that I initially tried this approach. I had problems with the pieces I was trying to animate suddenly flipping 180 degrees when the path turned a corner, and then flipping back when I turned another corner. Couldn’t figure out what was happening, so I went the other route to keep my pieces from flipping themselves across an axis without warning.

    Motion Graphics Designer
    Warm Springs Productions
    Missoula, Montana

  • Nate Biehl

    July 25, 2012 at 5:19 pm

    Dan, following the null works really well with 2D layers, no unexpected changes in orientation. If there is a way to get 2d layers to follow the null’s orientation along the path, all my problems would be solved!

    Motion Graphics Designer
    Warm Springs Productions
    Missoula, Montana

  • Dan Ebberts

    July 25, 2012 at 6:23 pm

    Try this for rotation:

    strt = 0; //start time of template motion
    end = 4.0; //end time of template motion

    t = thisComp.layer(“template”);
    offset = (t.effect(“offset”)(“Slider”)/100)*(index -1);
    travel = linear(t.effect(“travel”)(“Slider”)/100,strt,end);
    v = t.toWorldVec([1,0,0],travel – offset);
    radiansToDegrees(Math.atan2(v[1],v[0]))

    Dan

  • Nate Biehl

    July 25, 2012 at 7:40 pm

    Hi Dan,
    That seems to be closer, but the rotation is about -90 degrees off. I tried putting a transform effect on the segment, but that moves the anchor point and throws everything off.

    Is there any way to adjust the code to rotate the layer 90 degrees clockwise?

    Thank you for helping me iron this out.

    Motion Graphics Designer
    Warm Springs Productions
    Missoula, Montana

  • Dan Ebberts

    July 25, 2012 at 8:14 pm

    Sure– just add +90 (or -90, whichever works) to the end of the last line.

    Dan

  • Nate Biehl

    July 27, 2012 at 6:05 pm

    Thank you very much for your help, Dan. That did it!

    Motion Graphics Designer
    Warm Springs Productions
    Missoula, Montana

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