Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Ease a camera between variable positions using only expressions

  • Ease a camera between variable positions using only expressions

    Posted by Oliver Watson on October 26, 2017 at 1:40 am

    I may be close to a solution thanks to Dan’s amazing post on random motion with random durations: https://www.motionscript.com/mastering-expressions/random-1.html

    I’ve made a template for creating a dynamic Facebook timeline. The timeline shrinks or grows as you modify the number of posts, the size of the pictures, the number of comments, etc. so keyframes are not an option. Each post is its own comp, storing its own “height” and “image centre” (distance from the top of the post to its focal point which is the centre of the post’s main image) in slider controls.

    The problem: I’m trying to automate the movement of a camera so it eases from the image centre of one post to the next, and the next, and so on, until it reaches the end of the timeline. I’ve applied an expression to the Y Position of a null, but I can’t get the logic right. It seems like I need to declare the variable “endPos” on the 2nd last line without resetting it. Anyone know how I can do that? Or see a better solution?

    In summary, here’s the result I’m expecting:

    0 to 3 seconds: no movement
    3 to 8 seconds: move to an endPosition equal to the Image Centre of Post1
    8 to 13 seconds: move to an endPosition equal to the Image Centre of Post2 + the height of all previous posts
    13 to 18 seconds: move to an endPosition equal to the Image Centre of Post3 + the height of all previous posts
    18 to 23 seconds: move to an endPosition equal to the Image Centre of Post4 + the height of all previous posts
    and so on…

    currentLayer = 3;
    segDur = 5;
    segStart = 3; // start time of first segment
    segEnd = segStart + segDur; // end time of first segment
    startPos = 0;

    while ((time >= segEnd) && (currentLayer < (thisComp.numLayers - 2))){
    segStart = segEnd;
    segEnd += segDur;
    startPos = endPos;
    endPos = startPos + comp(thisComp.layer(currentLayer).name).layer("compData").effect("Post Height")("Slider");
    currentLayer += 1;
    }

    endPos += comp(thisComp.layer(currentLayer).name).layer("compData").effect("Image Centre")("Slider");
    ease(time, segStart, segEnd, startPos, endPos)

    Oliver Watson replied 8 years, 6 months ago 1 Member · 1 Reply
  • 1 Reply
  • Oliver Watson

    October 26, 2017 at 4:40 pm

    With help from Jeff Turnham I was able to fix it using functions:

    var offset = 1270; // starting position
    var segDur = 5;
    var timeSeg = Math.ceil((time - 3) / segDur); // the current time segment (post)
    var postAggregate = function(value) {
    var total = 0;
    var x = 1;
    while ((x < value) && (x < thisComp.numLayers - 2)) {
    total += comp(thisComp.layer(x+2).name).layer("compData").effect("Post Height")("Slider") + 100;
    x += 1;
    }
    total += comp(thisComp.layer(x+2).name).layer("compData").effect("Image Centre")("Slider");
    return total;
    };

    if (timeSeg < 1) {
    var segEnd = segDur + 3;
    var endPos = postAggregate(timeSeg+1) + offset;
    var startPos = 0 + offset;
    } else if (timeSeg < 2) {
    var segEnd = timeSeg * segDur + 3;
    var endPos = postAggregate(timeSeg) + offset;
    var startPos = 0 + offset;
    } else {
    var segEnd = timeSeg * segDur + 3;
    var endPos = postAggregate(timeSeg) + offset;
    var startPos = postAggregate(timeSeg - 1) + offset;
    }

    var segStart = segEnd - segDur;

    ease(time, segStart, segEnd, startPos, endPos);

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