Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions expression with springs

  • expression with springs

    Posted by David Miller on October 8, 2005 at 12:32 am

    I am trying to make an expression in which one layer (like text) is offset from a tracking point but moves with a dampened spring action as the tracking point moves around. Can anyone help me modify an expression that could be put on the position parameter but as position changes there would be a delayed motion but settle the position with a sine wave kind of action?

    Thanks so much
    David

    David Miller replied 20 years, 7 months ago 2 Members · 6 Replies
  • 6 Replies
  • Dan Ebberts

    October 8, 2005 at 2:02 am

    George Polevoy posted a good solution to this back in 2003 I think. Search the archives and you should find it.

    Dan

  • David Miller

    October 8, 2005 at 5:59 am

    Thanks Dan

    I did find that and have been trying to understand it. It is a little wild although giving it some preroll time seems to help and changing some of the parameters. But do you remember the motion math spring script. It was so perfect for doing little projects like this and it would add a dampening effect to the spring so it didn’t just bounce wildly. Do you know if I can repurpose that script? I suppose I could reload 5.5 and try to work with that or try to figure this one out but I don’t really know the quantitative differences between expressions and motion math.

    anyway thanks for the follow up.

    David

    Here was the script

    // One spring – version 1.2

    // This script attaches a spring between the 2 layers shown in the popups.
    // Layer 1 keeps its original motion, while layer 2 is attached by a spring to it.

    // LAYER PROPERTY CHANNEL
    // —— ———- ——–
    // 1: Layer that moves doesn’t matter doesn’t matter
    // 2: Layer attached to #1 by a spring doesn’t matter doesn’t matter

    if (time() == start_time) {
    rest_length = 10; // rest length of spring in pixels
    damp = 0.95; // Damping (0 = infinite friction, 1 = none)

    p1 = value(pop_layer(1), position);
    p2 = value(pop_layer(2), position);

    last_p1 = tmap(time() – step_time, value(pop_layer(1), position));
    last_p2 = tmap(time() – step_time, value(pop_layer(2), position));

    v1 = (p1 – last_p1);
    v2 = (p2 – last_p2);
    } else {
    p1 = value(pop_layer(1), position);

    delta = p2 – p1;
    n_delta = normalize(delta);

    a = 2 * n_delta * (length(delta) – rest_length) * step_time;

    v2 = (v2 – a) * damp;
    v1 = (v1 + a) * damp;

    p1 = p1 + v1;
    p2 = p2 + v2;
    }
    value(pop_layer(2), position) = p2;

  • Dan Ebberts

    October 8, 2005 at 6:27 am

    That particular MM script is one of the things that doesn’t translate well to expressions. It’s because expressions can’t have persistant variables so the expression has no idea what its value was on the previous frame. And the spring calculation really needs to know where everything was on the previous frame. With MM, the calculation for the entire timeline is done all at once, it’s not an issue.

    Dan

  • David Miller

    October 8, 2005 at 2:18 pm

    I finally understand. That must be why it lays down keyframes instead of dynamically updating as the parmeters change. Thanks for not letting me head down that direction. I wanted to play with some type following a tracking point but have it have action like the connections in that beautiful site https://www.visualthesaurus.com. In reality I can hand animate the whole thing which I may end up doing but this is one of those things that I just didn’t want to give up on. I know I could use it in the future and I know the community would take it into some amazing directions.

    Do you know if there is at least a dampening function that could be added to this?

    Thanks Dan

    David

  • Dan Ebberts

    October 8, 2005 at 10:53 pm

    You know, I just remebered that I had a brute-force method of doing the MM spring thing with expressions. It has to loop through the entire time line on every frame so it will undoubtedly bog down in long comps, but here it is:

    restLength = 20; //rest length (pixels)
    damp = .95;
    leader = thisComp.layer(“leader”);

    fDur = thisComp.frameDuration;
    currFrame = Math.round(time/fDur);

    p2 = position.valueAtTime(0);
    v2 = 0;
    for (f = 0; f <= currFrame; f++){ t = f*fDur; p1 = leader.position.valueAtTime(t); delta = p2 - p1; nDelta = normalize(delta); a = 2*nDelta*(length(delta) - restLength)*fDur; v2 = (v2 - a)*damp; p2 += v2; } p2 Dan

  • David Miller

    October 10, 2005 at 9:29 pm

    Thanks Dan

    I will give this a try on some short footage and report back from the front lines…

    david

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