Skip to main content
Peter J Kovacs
Inspiring
March 18, 2013
Question

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

  • March 18, 2013
  • 5 replies
  • 94563 views

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

5 replies

artichoked
Inspiring
February 3, 2022

If you get an error, try adding curly brackets to the if/else statement:

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

New Participant
May 16, 2020

HOW CAN I STOP THIS?

Community Expert
July 4, 2020

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

New Participant
August 31, 2018

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

New Participant
February 13, 2018

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?

ericsten
Inspiring
March 16, 2018

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

Dan Ebberts
Community Expert
March 18, 2013

Try this:

amp = 100;

freq = 1;

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

value + [0,y,0]

Dan

Participating Frequently
July 31, 2017

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.

Participating Frequently
August 1, 2017

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])


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])