ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

acceleration expression

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Jamie Bradshaw
acceleration expression
on Mar 27, 2018 at 3:14:03 pm

Hi all.

So I'm experimenting with a technique that I think would be very useful.

Basically, I created an expression that would use a layer's inPoint and outPoint along with a predefined start and end speed. It would then work out it's value as it accelerated from the start speed to the end speed.

Now I'd like to create an expression that you can apply to any property. Any keyframes in that property will represent the value's speed (per second) at that given point. The expression will then accelerate/decelerate according to what speeds you have set as keyframes.

I'm thinking that the best approach might be to store all the keyframe values and times in an array, and then calculate the value of the property using this array. I know that this could get quite slow though if there were lots of keyframes.

Anyway, before I got bogged down in trying to create this, I just wanted to see if anyone has attempted something similar or has a better idea/technique?

Cheers,
Jamie


Return to posts index

Steve Bentley
Re: acceleration expression
on Mar 28, 2018 at 6:42:23 am

This has come up quite a bit in the last two weeks. The problem is that the expressions have no memory to speak of. So the only way to "remember" things is to calculate values for every frame starting at frame 0 and work your way up to t=now. And you have to do that for each frame. Which is doable - but by the time you get to 1 min on your time line you are doing 3600 calculations per frame (and that's just for one attribute!)
The other problem is that there really isn't a "speed" or velocity attribute because every frame calculates position (in any form) for that frame only. And speed of course has a time factor.
Have a wander back through the past two weeks of after effects and after effects expression forums. Dan had some good insights into this very problem.



Return to posts index

Steve Bentley
Re: acceleration expression
on Mar 28, 2018 at 6:49:27 am

Here's one of the links. Bear with it, we didn't understand what the poster was after for a few back and forths.
The other thread isn't popping out at me but I'll keep looking - but it was within the last week, 2 at the max.
https://forums.creativecow.net/thread/2/1127988



Return to posts index


Scott McGee
Re: acceleration expression
on Mar 28, 2018 at 7:49:14 am

I can't take credit for this, but this works.

I've not been successful in getting this to work with a position expression yet, but I've not tried hard enough.

I usually do exponential scaling with a slider:

add a expression slider-control to your layer and rename the slider to "Z"

Give the layer's scale this expression:


exp = effect("Z")("Slider");
Math.pow(1.01,exp) * value;


Positive values for the slider => bigger, negative => smaller.
The nice thing about this is that you can ease the keyframes on that slider. Or even add an expression to it etc. (I usually add a smooth).
you can also still use the scale of the value if you need to flip or disproportiantely scale the layer because it get's mulitplied in.

If you want the 2D-position to also fake perspective (smaller= nearer to the vanishing point), add this expression to position:


exp = effect("Z")("Slider");

compCenter=[thisComp.width,thisComp.height]/2;

compCenter + Math.pow(1.01,exp) * (value-compCenter);


Note: if your layers are parented, stuff get's more complicated, so this will probably not look okay then.


Return to posts index

Steve Bentley
Re: acceleration expression
on Mar 28, 2018 at 8:24:08 am

Here's another link that might be helpful
http://www.motionscript.com/articles/speed-control.html



Return to posts index

Jamie Bradshaw
Re: acceleration expression
on Mar 28, 2018 at 12:16:00 pm

Ah, cheers Steve.. I missed this reply, and I should have had a look around at Dan's website first I guess... His overshoot stuff was a great resource for me.

I'll read through and see if I come out the other end with a clearer idea.


Return to posts index


Jamie Bradshaw
Re: acceleration expression
on Mar 28, 2018 at 8:45:23 am

Thanks Scott, although I'm not sure if my original question came through ok?

I'm looking to create an expression that I can apply to ANY property that will treat each keyframe value in that property as it's speed per second at that given time.

For example, lets say I'm using it on a layer's position property...

At frame 30, I create a keyframe of [0, 0]

At frame 60, I create a keyframe of [0, 100];

So between 30 and 60 frames, it would accelerate from a stationary point to 100 pixels per second in the y-axis.


Return to posts index

Jamie Bradshaw
Re: acceleration expression
on Mar 28, 2018 at 8:33:32 am

Cheers Steve.

Yeah I'm aware of the 'no memory' problem, but I was thinking that you could possibly make it more efficient by storing both the values and times of all the keyframes as an array, and then create a function that calculates the current value from that array (I know it still wouldn't be the quickest expression to execute).

Dan always has a great insight to these things so I'll have a dig around and see if I can find anything more.

Thanks, for your help.


Return to posts index

Steve Bentley
Re: acceleration expression
on Mar 28, 2018 at 7:30:42 pm

The issue of course is where to "store" that array.
I don't think you can write out a text or json object, if you could that could be your "RAM"



Return to posts index


Dan Ebberts
Re: acceleration expression
on Mar 28, 2018 at 7:54:44 pm

I don't think you gain anything by storing the keyframe values and times in an array because you already have easy access to those values. In general, based on the current value of time, you'd calculate the effect of all previous key frames. I'd do it by examining each segement between keyframes. For example, say you're currently somewhere between the 3rd and 4th keyframe. Assuming a linear interpolation, you could calculate the effect of the first segment by adding the value at keyframe 1 to the value at keyframe 2, dividing by 2 (to get the average) and multiplying by the time of keyframe 2 minus the time of keyframe 1. Then do the same thing for the second segment (between keyframe 2 and keyframe 3). Finally, calculate the effect of the partial segment between keyframe 3 and the current time. Something like that.


Dan



Return to posts index

Jamie Bradshaw
Re: acceleration expression
on Mar 29, 2018 at 9:26:48 am

Thanks Dan.

You've just brought clarity to the vague idea I had of approaching it. By 'storing it as an array' I meant something along the lines of using it to calculate all the previous sections and then the current one. I'm just not always as eloquent at describing it, but hey, I'm no coder! 😉

Thanks again!

JimJam•Graphics
http://www.jimjamgraphics.com/


Return to posts index

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