Skip to main content
brandonb96942845
Inspiring
June 18, 2022
Question

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

  • June 18, 2022
  • 2 replies
  • 637 views

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?

 

This topic has been closed for replies.

2 replies

Community Expert
June 19, 2022

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.

brandonb96942845
Inspiring
June 19, 2022

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.

Dan Ebberts
Community Expert
Community Expert
June 19, 2022

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]
Mylenium
Legend
June 18, 2022

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

brandonb96942845
Inspiring
June 18, 2022

I will give this a try! Many thanks.