ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Ease a camera between variable positions using only expressions

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Oliver Watson
Ease a camera between variable positions using only expressions
on Oct 26, 2017 at 1:40:57 am

I may be close to a solution thanks to Dan's amazing post on random motion with random durations: http://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 &lt; (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)


Return to posts index

Oliver Watson
Re: Ease a camera between variable positions using only expressions
on Oct 26, 2017 at 4:40:36 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 &lt; value) && (x &lt; 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 &lt; 1) {
var segEnd = segDur + 3;
var endPos = postAggregate(timeSeg+1) + offset;
var startPos = 0 + offset;
} else if (timeSeg &lt; 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);


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]