Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Accelerate position value

  • Accelerate position value

    Posted by Steve Renshaw on March 9, 2009 at 2:06 pm

    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]

    The following movie demonstrates 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.

    Brian Murray replied 14 years, 6 months ago 3 Members · 3 Replies
  • 3 Replies
  • Filip Vandueren

    March 9, 2009 at 5:04 pm

    Hi Steve,

    Expressions never keep a running total of what was calculated over the course of time, not even when you use + valueAtTime(),

    The correct way is to recalculate the running total from time=0 up to the current frame yourself.
    Like this:


    fd=thisComp.frameDuration;

    t=0;
    x=0;
    while (time>t) {
    acceleration = thisComp.layer("controls").effect("acceleration")("Slider").valueAtTime(t);
    x+=acceleration*fd;
    t+=fd;
    }

    value + [x,0];

    BTW, you’re not actually animating the rate of acceleration via the slider, but the velocity. I think that’s what you meant though.
    Acceleration=0 would mean, keep the current speed, not stand still.

  • Steve Renshaw

    March 9, 2009 at 6:56 pm

    Perfect! Thanks Filip.

  • Brian Murray

    January 19, 2012 at 6:45 pm

    This expression is great and does exactly as I would want it to, however, it causes the motion blur to calculate incorrectly. It seems to act as if all position keyframes were Hold Keyframes so it seems to not calculate the invisible in-between frames.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy