Skip to main content
kirynp57461627
Known Participant
August 29, 2024
Question

How can I fix this expression?

  • August 29, 2024
  • 1 reply
  • 262 views
Could someone help me with this expression. I am trying to get a position to bounce up and down with easing. The other requirement is that the oscillation should occur with the original position in the middle (so that when I adjust the sliders to zero, the position returns to where it was).

This is all part of an expression based animation. However - I'm having this issue where the easing occurs in the middle. So it slows down as it approaches the middle from it's peak. See video. It should be two smooth movements instead of three.  Any ideas @Dan Ebberts ?
 

 

var ctrl = thisComp.layer("Controller");
var bounceHeight = ctrl.effect("Bounce Height")("Slider");
var bounceSpeed = ctrl.effect("Bounce Speed")("Slider");


// Get the original position of the layer
var originalPos = transform.position;

// Calculate time-based phase for the bounce
var t = time * bounceSpeed;

// Create a time loop for continuous bouncing
var loopTime = 2 * Math.PI; // One full oscillation period
var loopProgress = (t % loopTime) / loopTime; // Normalized progress within one period

// Apply easing function to create a smooth bounce effect
var easedProgress = ease(loopProgress, 0, 1, 0, 1); // Eases from 0 to 1

// Calculate the vertical position with a bounce effect and easing
var bounceY = originalPos[1] + Math.sin(easedProgress * Math.PI * 2) * bounceHeight;

// Maintain the original X position
var bounceX = originalPos[0];

// Set the new position
[bounceX, bounceY];

 

This topic has been closed for replies.

1 reply

Dan Ebberts
Community Expert
Community Expert
August 29, 2024

I think the ease is messing things up. If you just use loopProgress instead of easedProgress, does that give you what you want?