Make a Layer Bounce Expression

//MAKE A LAYER BOUNCE:
bounceSpeed=7;
flight=01;
bounceHeight=3.5;
t=Math.abs((time*2*bounceSpeed)%2-1);
t=linear(t,flight,0,0,1);
b=Math.cos(t*Math.PI/2);
value - [0,bounceHeight*b];

This After Effects expression is designed to create a bouncing animation effect for a layer. Let’s go through it step by step:

  1. Variable Declarations:
    • bounceSpeed=7;: This variable determines the speed of the bounce. Higher values will make the bounce faster.
    • flight=01;: This variable represents the duration of the initial flight before the bounce begins. It’s set to 1 in this case.
    • bounceHeight=3.5;: This variable sets the maximum height of the bounce. Adjusting this value will change the height of the bounce.
  2. Time Calculation:
    • t=Math.abs((time*2*bounceSpeed)%2-1);: This line calculates a value t based on the current time.
      • time represents the current time in the composition.
      • Multiplying by 2 and bounceSpeed adjusts the speed of the animation.
      • %2 ensures that the value wraps around between 0 and 2.
      • Math.abs() ensures that the value is positive, and -1 shifts it down so that it oscillates between -1 and 1.
  3. Linear Interpolation:
    • t=linear(t,flight,0,0,1);: This line performs a linear interpolation on t.
      • It maps the range from flight (which is 1 in this case, representing the initial flight phase) to 0, to a range from 0 to 1.
      • This effectively creates a smooth transition from the initial flight phase to the bouncing phase.
  4. Bounce Calculation:
    • b=Math.cos(t*Math.PI/2);: This line calculates the bounce effect using the cosine function.
      • Math.PI/2 converts t from a range of 0 to 1 to a range of 0 to π/2 radians.
      • As t goes from 0 to 1, b oscillates between 1 and 0, creating the bounce effect.
  5. Applying Bounce Effect:
    • value - [0,bounceHeight*b];: Finally, this line applies the bounce effect to the layer’s position.
      • As b oscillates between 1 and 0, bounceHeight*b scales the bounce height accordingly, creating the bouncing animation effect.
      • The - [0,bounceHeight*b] subtracts this bounce effect from the original position value, causing the layer to move up and down in a bouncing motion.

In summary, this expression creates a bouncing animation effect for a layer based on the current time. Adjusting the variables bounceSpeed, flight, and bounceHeight allows for customization of the bounce speed, initial flight duration, and bounce height, respectively.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *