expression will only start at the beginning of an animation

Community Beginner ,
Aug 07, 2020

Copy link to clipboard

Copied

Hello, I am using this expression; 

freq = 1.0; //oscillations per second
amplitude = 50;
decay = 0.7;

amplitude*Math.sin(freq*time*2*Math.PI)/Math.exp(decay*time)

From this source (the pendulum with decay)http://www.motionscript.com/mastering-expressions/simulation-basics-3.html

I need this expression in the middle of my animation, however, it will only play the animation at the very beginning of my timeline, no matter where I place they keyframes. 
I also tried duplicating the asset with crtl+shift+d so that the animation might start at the split, however this did not work and the animation still played from the beginning, but since the beginning of the animation was cut off, it just resumed in the middle of the animation where the cut was instead of playing the whole expression.
Why is this happening, and how can I fix it? 

It depends on how you want to tell it when to start. If you know the time, you could do it like this (it will start at 2 seconds in this example):

 

tStart = 2;
freq = 1.0; //oscillations per second
amplitude = 50;
decay = 0.7;
t = Math.max(time - tStart,0);
amplitude*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t)

 

Dan

TOPICS
Error or problem, Expressions

Views

124

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

expression will only start at the beginning of an animation

Community Beginner ,
Aug 07, 2020

Copy link to clipboard

Copied

Hello, I am using this expression; 

freq = 1.0; //oscillations per second
amplitude = 50;
decay = 0.7;

amplitude*Math.sin(freq*time*2*Math.PI)/Math.exp(decay*time)

From this source (the pendulum with decay)http://www.motionscript.com/mastering-expressions/simulation-basics-3.html

I need this expression in the middle of my animation, however, it will only play the animation at the very beginning of my timeline, no matter where I place they keyframes. 
I also tried duplicating the asset with crtl+shift+d so that the animation might start at the split, however this did not work and the animation still played from the beginning, but since the beginning of the animation was cut off, it just resumed in the middle of the animation where the cut was instead of playing the whole expression.
Why is this happening, and how can I fix it? 

It depends on how you want to tell it when to start. If you know the time, you could do it like this (it will start at 2 seconds in this example):

 

tStart = 2;
freq = 1.0; //oscillations per second
amplitude = 50;
decay = 0.7;
t = Math.max(time - tStart,0);
amplitude*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t)

 

Dan

TOPICS
Error or problem, Expressions

Views

125

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
Aug 07, 2020 0
Guide ,
Aug 07, 2020

Copy link to clipboard

Copied

It depends on how you want to tell it when to start. If you know the time, you could do it like this (it will start at 2 seconds in this example):

 

tStart = 2;
freq = 1.0; //oscillations per second
amplitude = 50;
decay = 0.7;
t = Math.max(time - tStart,0);
amplitude*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t)

 

Dan

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
Reply
Loading...
Aug 07, 2020 0
Community Beginner ,
Aug 07, 2020

Copy link to clipboard

Copied

Is there anything I can do if I do not know an exact time? I kind of need to feel it out for exact placement due to the needs of my project, will I just have to experiment one second at a time?
Additionally, what can I do to have the animation start at half a second in, 2 and a half seconds in, and so on?

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
Reply
Loading...
Aug 07, 2020 0
Most Valuable Participant ,
Aug 08, 2020

Copy link to clipboard

Copied

You can manipulate the tStart variable in a million ways by referencing things like thisLayer.inPoint, markers or simply dialling in values via an expression slider. I would suggest you actually read the online help on the basics and watch some of the tutorials linked there rather than just relying on copy&paste code.

 

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
Reply
Loading...
Aug 08, 2020 0
Community Beginner ,
Aug 08, 2020

Copy link to clipboard

Copied

I know you are trying to be helpful, but you aren't. It is frustrating to be told "figure it out yourself" when asking a question. Yes I should be looking into the basics, but you didn't even answer my question and came off as rude. I can look into the help videos, but sitting through several videos looking for a single specific answer that may not even be covered in a video at all (such as, how do I write a half second value on a tstart) is a frustrating thing to be tasked with. I also learned of expressions existing literally yesterday, they were not covered in the class I took on after effects, I do not think I can learn how to code them all on my own in a single day. But regardless you could at least direct me to the videos in question about expressions, I don't even know where to find them. 
I don't mind learning, I came on this forum to ask questions and learn, but the way you told me to do so felt almost condencending and incredibly frustrating.

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
Reply
Loading...
Aug 08, 2020 0
Guide ,
Aug 08, 2020

Copy link to clipboard

Copied

Here are a few more examples. This one will start at the first layer marker (or at the layer's in point if there are no markers):

 

tStart = marker.numKeys > 0 ? marker.key(1).time : inPoint;
freq = 1.0; //oscillations per second
amplitude = 50;
decay = 0.7;
t = Math.max(time - tStart,0);
amplitude*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t)

 

This one will start at each layer marker (or not at all if no markers):

 

n = 0;
if (marker.numKeys > 0){
n = marker.nearestKey(time).index;
if (time < marker.key(n).time) n--;
}
tStart = n > 0 ? marker.key(n).time : 99999;
freq = 1.0; //oscillations per second
amplitude = 50;
decay = 0.7;
t = Math.max(time - tStart,0);
amplitude*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t)

 

This one will start at .5 seconds and every 2 seconds thereafter:

 

tStart = .5;
period = 2;
freq = 1.0; //oscillations per second
amplitude = 50;
decay = 0.7;
t = Math.max((time - tStart)%period,0);
amplitude*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t)

 

That should get you started.

 

Dan

 

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
Reply
Loading...
Aug 08, 2020 0
kk4pups LATEST
Community Beginner ,
Aug 08, 2020

Copy link to clipboard

Copied

Thank you so much!! This helped a lot!

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
Reply
Loading...
Aug 08, 2020 0