Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Use ease() expression with for loops

  • Use ease() expression with for loops

    Posted by Dan Smith on December 13, 2019 at 6:15 pm

    Hello everyone!

    I try to use “for” loop statement to create an expression with ease().
    Here is an example.

    I need to execute it for three times with three objects: Name1, Name2 and Name3, but it doesn’t work.
    I get only last interaction with Name3 object.

    Can you suggest me how can I execute ease() statement for three times with for loop?

    for (i = 1; i < 4; i++)

    {

    startM = thisComp.marker.key(1).time;

    stopM = thisComp.marker.key(2).time;

    xInPos = thisComp.layer("Name " + i).transform.position[0];

    yInPos = thisComp.layer("Name " + i).transform.position[1];

    xOutPos = thisComp.layer("Name " + (i+1)).transform.position[0];

    yOutPos = thisComp.layer("Name " + (i+1)).transform.position[1];

    x = ease(time, startM, stopM, xInPos, xOutPos);

    y = ease(time, startM, stopM, yInPos, yOutPos);

    [x, y, value]

    }

    Dan Smith replied 6 years, 8 months ago 3 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    December 13, 2019 at 7:21 pm

    At each frame, the result of an expression will be the last thing it calculates. What are you trying to get it to do?

    Dan

  • Dan Smith

    December 13, 2019 at 7:37 pm

    I have some pictures, which I add to the scene and into array.
    I have a camera object, which moves from object to object with ease expression and object’s coordinates.

    I need to move the camera from the first to the last picture consecutively with ease() or other. For e.x.: from “Name1” to “Name2”, from “Name2” to “Name3” etc. The number of interaction must be equal to the number of pictures.

    So I try to use for loop to do it.
    How can I do it in another way?

    xInPos = thisComp.layer("Name " + i).transform.position[0];
    xOutPos = thisComp.layer("Name " + (i+1)).transform.position[0];
    x = ease(time, 0, 20, xInPos, xOutPos);
    [x, value, value]

  • Dan Ebberts

    December 13, 2019 at 7:59 pm

    What’s controlling the timing of the moves, comp markers? If so, you expression needs to figure out which two markers the current time is between and use that to determine how far along it should be in the ease between the positions corresponding to those two markers. Something like this probably:


    m = thisComp.marker;
    if (m.numKeys > 0){
    n = m.nearestKey(time).index;
    if (time < m.key(n).time) n--;
    if (n == 0){
    val = thisComp.layer("Name " + 1).transform.position;
    }else if (n == m.numKeys){
    val = thisComp.layer("Name " + m.numKeys).transform.position;
    }else{
    inPos = thisComp.layer("Name " + n).transform.position;
    outPos = thisComp.layer("Name " + (n+1)).transform.position;
    val = ease(time, m.key(n).time, m.key(n+1).time, inPos, outPos);
    }
    [val[0],val[1],value[2]];
    }else
    value

    Dan

  • Andrei Popa

    December 13, 2019 at 8:24 pm

    Let me see if i understand you correctly. You have a comp with a bunch of pictures(the number may differ over time) and a camera. And you want the camera to hover over all the pictures with a preset animation/focus time. If so, you can use this


    animDur = 1;
    focusDur = 0.5;
    totalCycle = animDur+focusDur;
    otherLayers = 1;
    picsNumber = thisComp.numLayers-otherLayers;
    sector = Math.floor(time/totalCycle);
    x = (time < (picsNumber - 1)*totalCycle) ? ease(time, sector*totalCycle , sector*totalCycle+animDur, thisComp.layer("Name "+ (sector+1)).transform.position[0], thisComp.layer("Name "+ (sector+2)).transform.position[0]) : value[0];
    [x,value[1]]

    animDur is the duration of the movement from one picture to another;
    focusDur is how much the camera stays on a particular picture;
    otherLayers is the number of layers inside the comp that are not pictures named “Name 1”, “Name 2” etc
    For your information, if you put the picture from layer 1 towards bottom, you can use this(i think this variant is actually faster):

    animDur = 1;
    focusDur = 0.5;
    totalCycle = animDur+focusDur;
    otherLayers = 1;
    picsNumber = thisComp.numLayers-otherLayers;
    sector = Math.floor(time/totalCycle);
    x = (time < (picsNumber - 1)*totalCycle) ? ease(time, sector*totalCycle , sector*totalCycle+animDur, thisComp.layer(sector+1).transform.position[0], thisComp.layer(sector+2).transform.position[0]) : value[0];
    [x,value[1]]

    Andrei
    My Envato portfolio.

  • Dan Smith

    December 14, 2019 at 7:46 am

    Thanx to all. I try to use these variants.

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