Specific Counter Setup: Add Amount per Frame Until Value is Reached

Participant ,
Jun 18, 2022 Jun 18, 2022

Copy link to clipboard

Copied

Afternoon all,

 

Need some help to figure something out. Short version: I'm trying to create a setup where I can have a scene element fly into frame at a consistent speed, no matter how wide it is. What I want to do is have the item move a certain number of pixels from one frame to the next, until it's moved 100% of the width of the element.

 

In expression language, this is what I'm contemplating:

 

temp1 = this layer width;

temp2 = number of pixels to add each frame;

[expression to add temp2 per frame until the displacement equals 100% of temp1

 

I'm expecting to apply this to things of varying widths and what I'm looking for is to have them all move at a consistent rate of speed. Is this even possible with AE?

 

TOPICS
Expressions

Views

60

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 18, 2022 Jun 18, 2022

Copy link to clipboard

Copied

tWid=thisLayer.width;

tInc=2;

 

if(mX < tWid)

{mX=Math.floor(timeToFrames(time))*tInc}

else

{mX=tWid}

 

[mX,value[1]]

 

Of course this could be poured into a while() loop to potentially avoid the animation jumping and of course the time variable may need expanding to account for inPoints and whatever else you are doing.

 

Mylenium

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 18, 2022 Jun 18, 2022

Copy link to clipboard

Copied

I will give this a try! Many thanks.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 18, 2022 Jun 18, 2022

Copy link to clipboard

Copied

You can use sourceRectAtTime() to find the height and width of any layer. As long as the anchor point for that layer, or the Transform Shape/Position and Anchor Point, are at zero, the following expression will move any layer from the left edge of the frame to the center of the comp in 20 frames. If you want to change the move speed, change the * 20 to another value in the tMax variable. It works with any Text layer, shape layer, solid, or footage of any size as long as the Anchor Point or shape layer transforms have not been set to a different value.

 

 

 

 

 

 

ref = thisLayer;
trueX = ref.sourceRectAtTime().width /2;
value1 = - trueX * ref.scale[0] * .01;
value2 = thisComp.width/2;
t = time - inPoint;
tMin = 0;
tMax = thisComp.frameDuration * 20; // move in for 20 frames
x = easeOut(t, tMin, tMax, value1, value2);
y = thisComp.height / 2;

[x, y]

 

 

 

 

 

 

 It will work with footage, shape layers, or text layers if the paragraph justification is set to Centered. You can add the Top and Left values to fix paragraph alignment and baseline shift or multi-line problems with text layers. I have created about 30 auto-move presets that I created for animating Info Graphics and Slideshows. They fly layers in, bounce them to a stop, then fly them out or scale them out of the comp frame, always going to whatever position you place them just using the in and out points of the layers. 

 

If you are fairly good with expressions, you should be able to modify that expression to move layers down from the top, up from the bottom, or in from the right. You can modify that expression, so the left or right edge of the layer stops at a specific spot in the comp or the layer's original position. 

 

I hope this helps.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 18, 2022 Jun 18, 2022

Copy link to clipboard

Copied

I'm still trying to get Mylenium's expression to work right but this one doesn't sound like it does what I'm looking for. What you're describing is what I could do with a slider. I know how to get the translation to happen in a set number of frames. What I'm asking for is something more complex.

 

Basically, I'm going to have rectangles of varying widths flying in from out of frame, and I want them all to come in at a consistent speed. So basically, if I have a bar of width 250, and a bar of width 550, I want them to fly in from out of frame at the same rate (in other words, the same number of pixels per frame) until they're all the way in. This means they'll be in motion for different durations, but at the same rate of speed.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 18, 2022 Jun 18, 2022

Copy link to clipboard

Copied

Something like this maybe:

tStart = inPoint; // time to start move
rate = 250; // speed (pixels per second)

w = sourceRectAtTime(0,false).width;
dur = w/rate;
x = linear(time,tStart,tStart+dur,0,w);
value + [x,0]

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 19, 2022 Jun 19, 2022

Copy link to clipboard

Copied

Dan's expression will give you a constant speed, but the ending position will depend on the width. I assume that you want the starting position to have the right edge of the shape just out of frame on the left side, then end up with the left edge of the shape at the same place for each layer. The result would be multiple bars moving into position, so the left edges were all lined up, but the move speed would be constant. Did I get that right?

Start:

RickGerard_0-1655650122258.png

 

End:

RickGerard_1-1655650142112.png

If that is the case, I'll have to fiddle with the expression so that speed is constant and starting and ending position depends on the shape's width. It might take me a minute. It's an interesting problem.

 

It took about two minutes to come up with this: 

 

 

 

frmNo = (time - inPoint) / thisComp.frameDuration;
mov = 20 * frmNo; // 20 pixels per frame;
strtX = - sourceRectAtTime().width / 2;
endX = value[0] - strtX;
x = strtX + mov;

if (x < endX)
	x = x;
else
	x = endX

y = value[1];
[x, y]

 

 

It will take me a little longer to put some easing in the expression, so the move looks more natural, but this will keep all layers moving at the same speed from the left edge until they get to the original layer position.

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 19, 2022 Jun 19, 2022

Copy link to clipboard

Copied

LATEST

Now you're talking! I anticipate them mostly coming in from right of frame but that's an easy change from adding pixels to subtracting them.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines