Skip to main content
Participating Frequently
June 13, 2020
Answered

Help with expression for position incremental stepping.

  • June 13, 2020
  • 2 replies
  • 3298 views

Hello,

 

My project has a block of animated text that I would like to animate incramental postion. Evert ten frames, I want the position of the layer to move x amount on the Y axis. Much like the ticking of a clock, only linear. I have tried the following expression, and it works great for fluid motion, but as I have stated, I want stepping motion at a specific incriment. 

t = time;

s = 60;

v = t * s;

[value[0], value[1] + v]

I know it is something pretty simple, but I am having a tough time finding such a specific answer. Any help would be appreciated.

 

Thanks!

This topic has been closed for replies.
Correct answer Rick Gerard

If you want the property to jump in value every X number of frames all you have to do is divide the frame number of frames by the number of frames you want between moves, round the result, then multiply the property value you want to move by the change in value. Let's say that every 10 frames you wanted the Y position of a text layer to move up in y by 40 pixels. Let's start with the math, then build a value + array that lets you set the start position anywhere you want.

 

// set freqency and distance
countFrames = time/thisComp.frameDuration;
freq = countFrames / 10;
jump = Math.round(freq);
newY = jump * 40;
// Create Array
[value[0], value[1] - newY]]

 

This could also be used to set the jump time to decimal parts of a second instead of frames.

 

If the timing needed to be seconds, no matter what the frame rate is you would use Time instead of Time/Frame Duration.  Let's say you wanted to have a second hand that snaps from one number to the next every second. The math is really simple there too. A clock face has 60 seconds in 360º so each second the second hand must jump 6º. The expression would use the same math round operator but you would not need to create an array. It would look like this:

 

// Universal Second Hand
value + Math.round(time) * 6

 

 

2 replies

Rick GerardCommunity ExpertCorrect answer
Community Expert
June 13, 2020

If you want the property to jump in value every X number of frames all you have to do is divide the frame number of frames by the number of frames you want between moves, round the result, then multiply the property value you want to move by the change in value. Let's say that every 10 frames you wanted the Y position of a text layer to move up in y by 40 pixels. Let's start with the math, then build a value + array that lets you set the start position anywhere you want.

 

// set freqency and distance
countFrames = time/thisComp.frameDuration;
freq = countFrames / 10;
jump = Math.round(freq);
newY = jump * 40;
// Create Array
[value[0], value[1] - newY]]

 

This could also be used to set the jump time to decimal parts of a second instead of frames.

 

If the timing needed to be seconds, no matter what the frame rate is you would use Time instead of Time/Frame Duration.  Let's say you wanted to have a second hand that snaps from one number to the next every second. The math is really simple there too. A clock face has 60 seconds in 360º so each second the second hand must jump 6º. The expression would use the same math round operator but you would not need to create an array. It would look like this:

 

// Universal Second Hand
value + Math.round(time) * 6

 

 

MistaJEAuthor
Participating Frequently
June 13, 2020

I just used this expression and inserted the position offset that I calculated, and it works absolutely flawlessly. Thank you again.

Participant
June 13, 2020

There's probably a way to code that in an expression, but you can't use a global variable in AE, so you would need to write a very messy code just to reproduce this effect. You are better off using keyframes for this IMO.