Accelerate position value
Posted: March 9th, 2009, 4:37 am
Hi,
I'm trying to animate a position value using an expression control slider to influence the acceleration of the movement. I've keyframed an acceleration control to increase from zero to 50 and back to zero over a number of frames. I want the position value to increase as the acceleration controller is increased, and the rate of increase to reduce as the controller value is reduced, but not to move backwards (unless a negative value is used on the controller).
My initial expression moved the position value according to the acceleration controller, but as soon as the controller value reduces, the position movement stops and goes back to where it came from. I think the correct logic would be to "Add the acceleration slider value to the PREVIOUS frame's position value". This would ensure that the position value would always be greater or equal to the previous frame, and would not travel backwards when it should simply be slowing down.
My latest version of the expression code is as follows, but it still causes the position to move back to where it started:
acceleration = thisComp.layer("controls").effect("acceleration")("Slider");
old_frame = timeToFrames(time-1);
oldX = position.valueAtTime(old_frame)[0];
X= oldX + acceleration;
Y= position[1];
[X,Y]
I've uploaded a GIF to show the problem - the yellow square shows the motion I'm trying to create, the orange square shows the results of the above expression.
What am I doing wrong?
Thanks in advance,
Steve.
I'm trying to animate a position value using an expression control slider to influence the acceleration of the movement. I've keyframed an acceleration control to increase from zero to 50 and back to zero over a number of frames. I want the position value to increase as the acceleration controller is increased, and the rate of increase to reduce as the controller value is reduced, but not to move backwards (unless a negative value is used on the controller).
My initial expression moved the position value according to the acceleration controller, but as soon as the controller value reduces, the position movement stops and goes back to where it came from. I think the correct logic would be to "Add the acceleration slider value to the PREVIOUS frame's position value". This would ensure that the position value would always be greater or equal to the previous frame, and would not travel backwards when it should simply be slowing down.
My latest version of the expression code is as follows, but it still causes the position to move back to where it started:
acceleration = thisComp.layer("controls").effect("acceleration")("Slider");
old_frame = timeToFrames(time-1);
oldX = position.valueAtTime(old_frame)[0];
X= oldX + acceleration;
Y= position[1];
[X,Y]
I've uploaded a GIF to show the problem - the yellow square shows the motion I'm trying to create, the orange square shows the results of the above expression.
What am I doing wrong?
Thanks in advance,
Steve.