Accelerate position value

Moderators: Disciple, zlovatt

Post Reply
DIGITALmotion
Posts: 3
Joined: September 11th, 2008, 1:43 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.
test.gif
test.gif (10.97 KiB) Viewed 14151 times
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

The biggest problem is that an expression can't access values that it calculated at previous frames. When an expression references the property to which it is applied, it gets back the pre-expression value. It can, however, access previous values of the slider. So you can set up a loop that starts at frame zero and calculates the effect of the acceleration slider at each frame up to the current frame.

Dan
kobyg
Posts: 128
Joined: December 7th, 2007, 10:11 am

Try this expression:
(Link your acceleration slider to the v variable in the expression)

Code: Select all

Td = framesToTime(1, 1.0 / thisComp.frameDuration);
x = 0;
v = effect("acceleration")("Slider");
n = timeToFrames(time + thisComp.displayStartTime,  1.0 / thisComp.frameDuration);
for (k=0; k<=n; k++)
     x = x + v.valueAtTime(k*Td);

x = x + position[0];
y = position[1];
[x,y]
Koby.

p.s.: What you call "acceleration" is actualy the velocity...
A negative velocity will make the layer go the opposite direction.
note: As the time increases, the calculation would be slower. So try using it on short compositions.
Post Reply