Highlighted

## Oscillate Y value between two designated points

Community Beginner ,
Jul 26, 2020

Copied

I would like to be able to write an expression that will translate my Y position value between two numbers evenly. Wiggle won't work because wiggle is random. Instead, I want to write an expression that allows my Y value to oscillate back and forth between two points at the same speed/frequency.

For example:

If my y postion value is set to 540, I would like it to move between 540 and 550 at the same speed. Like a bouncey ball that never looses it's bounce.

There are lots of ways to do what you want to do. If you use Wiggle you'll get random values. For Example:

``````wgl = wiggle(4, 50);
[value, wgl ]``````

Will give you this (Graph Editor Value Graph to show you the random Y value) Your ball would bounce continuously but the height would vary.

You could use the Math.sin(time * (Math.PI * 10)) function to create a smooth change from 0 to 1 and then 0 to -1 5 times a second. Multiply that value by the number of pixels you want to have the layer move and you end up with this:

``````y = Math.sin(time * (Math.PI * 10));
[value, value + y * 100]`````` If you want a bouncing ball where the ball decelerates as it rises and then accelerates as it falls you would start by setting two keyframes with the same value for y but different values for x. If you wanted the oscillations to happen every 10 frames the first step would look like this: Then you would switch to the pen tool and use the Convert Vertex tool by holding down the Alt/Option key and drag out the bezier handles on the motion path so the ball moved to the apex of the bounce on frame five like this: I've turned on the Grid to help make the motion path symmetrical. The last step before adding the expression would be to adjust the Speed graph so the acceleration looks like this. You want instant acceleration to max speed when the ball hits the ground. Auto Bezier is the right tool in Graph Editor. and this is what the graph looks like; You want the speed to be zero halfway between the keyframes and a deceleration then acceleration curve on either side. pulling the control handles all the way toward each other and matching the speed will give you a decent approximation of gravity.

Then a simple loopOut("pingpong") expression will give you a ball that bounces up and down. Resetting the position properties of both keyframes to the center of the comp and matching up both path vertex handles so they are vertical will give you a ball that continuously bounces up and down. You can use a combination of loopOut("pingpong"), and loopOut("offset") to make the ball continuously bounce up and down while moving across the screen. Here's the expression for a ball bouncing in place;

``````y = loopOut("pingpong");
[value, y]``````

You could leave the starting and ending positions different and keep the path the same, then add this expression with separate loop operators for X and Y and end up with a ball that bounced across the screen.

That should get you started.

Topics

Expressions

Views

55

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more ## Oscillate Y value between two designated points

Community Beginner ,
Jul 26, 2020

Copied

I would like to be able to write an expression that will translate my Y position value between two numbers evenly. Wiggle won't work because wiggle is random. Instead, I want to write an expression that allows my Y value to oscillate back and forth between two points at the same speed/frequency.

For example:

If my y postion value is set to 540, I would like it to move between 540 and 550 at the same speed. Like a bouncey ball that never looses it's bounce.

There are lots of ways to do what you want to do. If you use Wiggle you'll get random values. For Example:

``````wgl = wiggle(4, 50);
[value, wgl ]``````

Will give you this (Graph Editor Value Graph to show you the random Y value) Your ball would bounce continuously but the height would vary.

You could use the Math.sin(time * (Math.PI * 10)) function to create a smooth change from 0 to 1 and then 0 to -1 5 times a second. Multiply that value by the number of pixels you want to have the layer move and you end up with this:

``````y = Math.sin(time * (Math.PI * 10));
[value, value + y * 100]`````` If you want a bouncing ball where the ball decelerates as it rises and then accelerates as it falls you would start by setting two keyframes with the same value for y but different values for x. If you wanted the oscillations to happen every 10 frames the first step would look like this: Then you would switch to the pen tool and use the Convert Vertex tool by holding down the Alt/Option key and drag out the bezier handles on the motion path so the ball moved to the apex of the bounce on frame five like this: I've turned on the Grid to help make the motion path symmetrical. The last step before adding the expression would be to adjust the Speed graph so the acceleration looks like this. You want instant acceleration to max speed when the ball hits the ground. Auto Bezier is the right tool in Graph Editor. and this is what the graph looks like; You want the speed to be zero halfway between the keyframes and a deceleration then acceleration curve on either side. pulling the control handles all the way toward each other and matching the speed will give you a decent approximation of gravity.

Then a simple loopOut("pingpong") expression will give you a ball that bounces up and down. Resetting the position properties of both keyframes to the center of the comp and matching up both path vertex handles so they are vertical will give you a ball that continuously bounces up and down. You can use a combination of loopOut("pingpong"), and loopOut("offset") to make the ball continuously bounce up and down while moving across the screen. Here's the expression for a ball bouncing in place;

``````y = loopOut("pingpong");
[value, y]``````

You could leave the starting and ending positions different and keep the path the same, then add this expression with separate loop operators for X and Y and end up with a ball that bounced across the screen.

That should get you started.

Topics

Expressions

Views

56

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more Jul 26, 2020

Copied

There are lots of ways to do what you want to do. If you use Wiggle you'll get random values. For Example:

``````wgl = wiggle(4, 50);
[value, wgl ]``````

Will give you this (Graph Editor Value Graph to show you the random Y value) Your ball would bounce continuously but the height would vary.

You could use the Math.sin(time * (Math.PI * 10)) function to create a smooth change from 0 to 1 and then 0 to -1 5 times a second. Multiply that value by the number of pixels you want to have the layer move and you end up with this:

``````y = Math.sin(time * (Math.PI * 10));
[value, value + y * 100]`````` If you want a bouncing ball where the ball decelerates as it rises and then accelerates as it falls you would start by setting two keyframes with the same value for y but different values for x. If you wanted the oscillations to happen every 10 frames the first step would look like this: Then you would switch to the pen tool and use the Convert Vertex tool by holding down the Alt/Option key and drag out the bezier handles on the motion path so the ball moved to the apex of the bounce on frame five like this: I've turned on the Grid to help make the motion path symmetrical. The last step before adding the expression would be to adjust the Speed graph so the acceleration looks like this. You want instant acceleration to max speed when the ball hits the ground. Auto Bezier is the right tool in Graph Editor. and this is what the graph looks like; You want the speed to be zero halfway between the keyframes and a deceleration then acceleration curve on either side. pulling the control handles all the way toward each other and matching the speed will give you a decent approximation of gravity.

Then a simple loopOut("pingpong") expression will give you a ball that bounces up and down. Resetting the position properties of both keyframes to the center of the comp and matching up both path vertex handles so they are vertical will give you a ball that continuously bounces up and down. You can use a combination of loopOut("pingpong"), and loopOut("offset") to make the ball continuously bounce up and down while moving across the screen. Here's the expression for a ball bouncing in place;

``````y = loopOut("pingpong");
[value, y]``````

You could leave the starting and ending positions different and keep the path the same, then add this expression with separate loop operators for X and Y and end up with a ball that bounced across the screen.

That should get you started.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more LATEST
Community Beginner ,
Jul 27, 2020

Copied

This is exactly what I as looking to do and so much more. Thank you for such an in depth explaination and even a look into some other functions. I really appreciate the time and care you took in answering my question. This is amazing. Thank you so much and God bless you!

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more Resources Troubleshooting
Knowledge Base Articles
Getting Started