Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions linear() but with more than two sets of variables?

Tagged: 

  • linear() but with more than two sets of variables?

    Posted by Tim Parsons on March 21, 2023 at 3:15 pm

    I’m creating a PremierePro Mogrt in AE’s Essential graphics, so most things in my project need to be dynamic and controllable with sliders. I’m animating an object from point A to point B using linear() tied to a slider to animate it, rather than using keyframes. As the slider goes from 0 to 1, the object moves in a straight line between the two points.

    s = effect("A to B")("Slider");
    x=effect("Callout Start")("Point");
    y=effect("Callout End")("Point");
    n1=x[0];
    n2=x[1];
    n3=y[0];
    n4=y[1];
    s1=linear(s, 0,1, n1, n3);
    s2=linear(s, 0,1, n2, n4);
    [s1,s2];

    So far so good. Now I’d like to dynamically adjust the midpoint of that line, so the object goes from A to C to B.

    My thought process is that I would calculate the midpoint of the imaginary line from A to B on a point controller, then use another point controller to add an offset value to the first point controller (the offset controller is what would be added to the mogrt essential graphics, fyi).

    Where I’m getting stuck is making the position of that midpoint have any affect on the location of the object as it travels from A to B. I’d like to be able to add “.5” as an input variable in the linear() expression, with a link to the first point controller as the output variable, but alas, linear() can only have 3 or 5 arguments. What I’m looking for would be 7.

    Any ideas for how to accomplish this?

    Brie Clayton replied 11 months ago 3 Members · 5 Replies
  • 5 Replies
  • Filip Vandueren

    March 21, 2023 at 3:32 pm

    Here’s one way of how to do it:

    s = effect("A to B")("Slider");
    startP = effect("Callout Start")("Point");
    endP = effect("Callout End")("Point");
    midP = effect("Callout Middle")("Point");
    linear(s, 0, 0.5, startP,midP)
    +
    linear(s, 0.5, 1, midP,endP)
    -midP;

    or like this:

    s = effect("A to B")("Slider");
    startP = effect("Callout Start")("Point");
    endP = effect("Callout End")("Point");
    midP = effect("Callout Middle")("Point");
    if (s<0.5) {
    linear(s, 0, 0.5, startP,midP)
    } else {
    linear(s, 0.5, 1, midP,endP)
    }

    You may want to “balance” the timting midpoint, because if it is not located equally distant from start and end, then the animation would speed up/slow down before and after 0.5.

    This is a possible way to do that:

    s = effect("A to B")("Slider");
    startP = effect("Callout Start")("Point");
    endP = effect("Callout End")("Point");
    midP = effect("Callout Middle")("Point");
    midWay = length(startP, midP) / (length(startP, midP) + length(midP, endP));
    if (s<midWay) {
    linear(s, 0, midWay, startP,midP)
    } else {
    linear(s, midWay, 1, midP,endP)
    }
  • Tim Parsons

    March 21, 2023 at 6:22 pm

    Brilliant. The first one worked right away, so I didn’t try the others. Thanks!

  • Brie Clayton

    March 22, 2023 at 1:41 pm

    Filip Vandueren

  • Filip Vandueren

    March 23, 2023 at 9:18 am

    Yes? Brie?

  • Brie Clayton

    March 23, 2023 at 4:10 pm

    Haha, I’m trying to implement a reasonable, low-key, but congratulatory way to publicly recognize that you have solved Tim Parson’s issue.

    The gamification could only be modeled so much before we rolled it out on Creative COW’s gigantic platform, so some of these things we have to figure out as we go along. A page to outline the rules and methods for earning these points is forthcoming, but we have to iron out all the kinks first. Soon all will be crystal clear!

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