Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity › Forums › Adobe After Effects Expressions › Incorrect layer movement expression

  • Incorrect layer movement expression

    Posted by Boris Norkin on December 7, 2020 at 3:49 pm

    Hi there!

    I have such an expression on a position of a layer:

    var distance = [0,0];
    var p0 = toComp(anchorPoint, 0);
    var res = [0,0];
    for(var cF = 0; cF < timeToFrames(time); cF++)
    {
    distance = (thisComp.layer(“Target Layer”).toComp(anchorPoint) – toComp(anchorPoint, time – 0.1)) * 0.5;
    res += distance;
    }
    p0 + res

    The idea was that at the first frame the layer would go 1/2 of the distance to a target layer. Next frame 1/4 and etc.
    And if I move the target layer the layer with an expression should smoothly change its direction to it.

    But instead I got an uniform movement of the layer in direction of the target layer.

    Is there a mistake in that expression or am I just not understanding how expressions work and, for example, AE can’t let an expression to refer to its state in a previous frame or something like that?

     

    Dan Ebberts replied 5 years, 9 months ago 2 Members · 1 Reply
  • 1 Reply
  • Dan Ebberts

    December 7, 2020 at 5:12 pm

    >for example, AE can’t let an expression to refer to its state in a previous frame or something like that?

    That’s correct. However, it looks like your expression is already set up to loop through all previous frames (which is one way to work around the expressions-have-no-memory issue). You can take advantage of the time parameter of toComp() to get the frame-by-frame position of the target layer:

    thisComp.layer("Target Layer").toComp(anchorPoint,framesToTime(cF))

    and use that to calculate on the fly how the layer with the expression should respond on a frame-by-frame basis.

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