Highlighted

How to create a simple bobbing up and down motion expression?

Contributor ,
Mar 18, 2013

Copy link to clipboard

Copied

Hi, I have a 3D object that I want to continuously bob up and down but I'm having trouble finding an expression to do this.

I would use wiggle on the Z except wiggle creates random motion and I need consistant up and down oscillations.

It seems simple but I can't figure it out... any ideas? Thanks.

-Pete

Topics

Expressions, How to

Views

34.4K

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

How to create a simple bobbing up and down motion expression?

Contributor ,
Mar 18, 2013

Copy link to clipboard

Copied

Hi, I have a 3D object that I want to continuously bob up and down but I'm having trouble finding an expression to do this.

I would use wiggle on the Z except wiggle creates random motion and I need consistant up and down oscillations.

It seems simple but I can't figure it out... any ideas? Thanks.

-Pete

Topics

Expressions, How to

Views

34.4K

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
Guide ,
Mar 18, 2013

Copy link to clipboard

Copied

Try this:

amp = 100;

freq = 1;

y = amp*Math.sin(time*freq*Math.PI*2);

value + [0,y,0]

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...
Contributor ,
Mar 18, 2013

Copy link to clipboard

Copied

Wow Dan, that works perfectly... thanks for the help!

It would be cool if wiggle had an option to control the randomness so I can get the same results as your expression.

-Pete

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...
New Here ,
Dec 19, 2016

Copy link to clipboard

Copied

Hi Dan,

Please can you tell me which wiggle preset you use?

Many thanks,

Lisa

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...
Guide ,
Dec 19, 2016

Copy link to clipboard

Copied

I'm not sure what you mean. I don't use a wiggle preset.

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...
New Here ,
Jun 02, 2017

Copy link to clipboard

Copied

Hi Dan - your solution is a lifesaver. Pretty new still to a Position Express - if I wanted to do a horizontal shake back and forth rather than up and down like your code, what would that look like? I tried subbing in X for Y values but that didn't work. Much appreciated!

Julie

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...
Guide ,
Jun 02, 2017

Copy link to clipboard

Copied

This should work:

amp = 100;

freq = 1;

x = amp*Math.sin(time*freq*Math.PI*2);

value + [x,0,0]

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...
New Here ,
Jun 02, 2017

Copy link to clipboard

Copied

Amazing, it worked! thank you 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...
New Here ,
Oct 07, 2018

Copy link to clipboard

Copied

Hi, Dan -

How exactly are you designating x and y as targets for the expression?  I understand x = or y = _____, but I am getting lost when you write things like [0,x,0] and so forth.  I think arrays when I see [ ], but I don't understand what the arguments are inside those brackets.

For instance, say I wanted to oscillate on both the y and z axis'?  What about cos on y and sin on z?

Many thanks!

Billy B

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...
New Here ,
Oct 07, 2018

Copy link to clipboard

Copied

Oh wait I think I got it...  Inside of the brackets goes the arguments for the x y and z.  So it's ...

value + [x,y,z]

Here's the code you gave modified to oscillate on the y axis by sin and the z axis by cosine.

ampY = 10;

ampZ = 10;

freqY = 1;

freqZ = 1;

y = ampY*Math.sin(time*freqY*Math.PI*2);

z = ampZ*Math.cos(time*freqZ*Math.PI*2);

value + [0,y,z]

This post really helped a lot!!  Seems like the folks who write the how-to's on the Adobe website are engineers and can't think like a doofus (like me LOL).

Cheers!


BB

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...
Community Beginner ,
Jul 31, 2017

Copy link to clipboard

Copied

Hey Dan I am kind of new to after effects and I understand expressions but I honestly not sure where you post these lines. Can you help out? Would be much appreciated.

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...
Guide ,
Jul 31, 2017

Copy link to clipboard

Copied

These are Position expressions. Is that what you meant?

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...
Community Beginner ,
Jul 31, 2017

Copy link to clipboard

Copied

Yes that was! Thank you so much! How can I get this to start at a specific time?

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...
Explorer ,
Aug 01, 2017

Copy link to clipboard

Copied

try subbing this for the last line of Dan's expression.

t=time; // Comp Time //

StartTime=2; // time in seconds | change this to when you want it to start //

if (t < StartTime) value else (value + [x,0,0])

so that the end result is:

amp = 100;

freq = 1;

x = amp*Math.sin(time*freq*Math.PI*2);

t=time;                                // Comp Time //

StartTime=2;                      // time in seconds | change this to when you want it to start //

if (t < StartTime) value else (value + [x,0,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
Reply
Loading...
Community Beginner ,
Aug 01, 2017

Copy link to clipboard

Copied

Thanks a ton for the help! How do I format the time that I need to enter? I'm still new to expressions.

This is what my expression lines look like but it starts at the beginning still.

amp = 15;

freq = 1;

y = amp*Math.sin(time*freq*Math.PI*2);

t=time;                                // Comp Time //

StartTime=2;                      // 07:45 //

if (t < StartTime) value else (value + [0,y,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
Reply
Loading...
Explorer ,
Aug 02, 2017

Copy link to clipboard

Copied

Future reference  anything inside of forward slashes in expressions are just comments. By using a double slash, that means that section of text, etc are not "seen"by the software.

I highly recommend doing the JavaScript course on CodeCademy's website, it's free and very helpful for first time coders. It's not a direct application to AfterEffects, but most of the information like setting up variables and using if, or, else statements hold true.

To adjust the StartTime, change the "2" to whatever time you want in seconds.

Based on your reference above ^ you want it to start at 7 minutes and 45 seconds. This would be 465 seconds, so...

amp = 15;

freq = 1;

y = amp*Math.sin(time*freq*Math.PI*2);

t=time;                                // Comp Time //

StartTime=465;                      // Start Time of Bobbing effect //

if (t < StartTime) value else (value + [0,y,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
Reply
Loading...
New Here ,
Aug 15, 2017

Copy link to clipboard

Copied

How do I do the same thing but for rotation?

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...
Explorer ,
Aug 15, 2017

Copy link to clipboard

Copied

Instead of setting up for an [X, Y] coordinate, you use the same expression but for a single number ouput.

amp = 15;

freq = 1;

R = amp*Math.sin(time*freq*Math.PI*2);

t=time;                                // Comp Time //

StartTime=465;                      // Start Time of Bobbing effect //

if (t < StartTime) value else (value + )

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...
New Here ,
Jun 28, 2019

Copy link to clipboard

Copied

Dan you mad man that is incredible

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...
New Here ,
Jul 10, 2019

Copy link to clipboard

Copied

thanks a ton for this script Dan,

I wonder if there would be a way to add a time interpolation to this expression, so that it animates every other frame - on twos or in threes for example which is very useful for animation techniques.

something like

tStep = framesToTime(x);

where x would be how many frames it holds before advancing to the next interpolation? hope it makes sense?

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...
Guide ,
Jul 10, 2019

Copy link to clipboard

Copied

You could start the expression with this to set the frame rate:

posterizeTime(15)

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...
New Here ,
Jul 10, 2019

Copy link to clipboard

Copied

great, simple and effective. 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
Reply
Loading...
New Here ,
Jul 13, 2019

Copy link to clipboard

Copied

Dan you After effects legend, is there possibly a way to reduce the distance of the bobbing? so it's a little softer. The expression is perfect but it bobs too far, from the bottom of my composition to the top!

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...
Guide ,
Jul 13, 2019

Copy link to clipboard

Copied

Just change the value of the amp variable to something smaller.

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...
New Here ,
Jul 03, 2020

Copy link to clipboard

Copied

Hey Dan, 

I'm currently using this expression for a small project I'm working on, it works amazingly, but I need help with an adjoining element. I'm attempting to add a circular shadow underneath the object I have floating using your expression, but I'm wondering if it's possible to have the shadow underneath expanding and contracting in the same tempo and style as the object above it, does this make sense to you at all?

 

Best,

Myles

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...
Guide ,
Jul 03, 2020

Copy link to clipboard

Copied

You might try something like this for Size or Scale (make sure the freq variable matches your other exrpession):

 

amp = 20;
freq = 1;
s = amp*Math.sin(time*freq*Math.PI*2);
value*(1+s/100)

 

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...
Community Beginner ,
Feb 12, 2018

Copy link to clipboard

Copied

Hey guys, sorry to revive this but the expression is really great. I'm trying to use it for the z-axis and so far it worked the only thing I'm stuck with is how to create only positive values for the amplitude. Any idea on how to do this?

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...
Explorer ,
Mar 15, 2018

Copy link to clipboard

Copied

Sorry for the late response.

One way to achieve this is by adding Math.abs() to your expression which will return the absolute values instead of true values (aka negative numbers get switched to positive).

Z=Math.abs(amp*Math.sin(time*freq*Math.PI*2));

- Eric

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...
New Here ,
Aug 31, 2018

Copy link to clipboard

Copied

Hi all,

The expression worked great. But i have no idea on if it is possible to decelerate the "bobbing/bopping" motion.

Do i need to adjust the value or frequency?

Thanks guys! x

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...
New Here ,
May 15, 2020

Copy link to clipboard

Copied

HOW CAN I STOP THIS?

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...
Adobe Community Professional ,
Jul 03, 2020

Copy link to clipboard

Copied

Stop or start the effect by controlling amp and freq with sliders then animate the sliders.

Screenshot_2020-07-03 20.49.13_GtIOt2.png

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...