Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions derekd – here’s your spring expression

  • derekd – here’s your spring expression

    Posted by Dan Ebberts
    on April 8, 2005 at 5:58 pm

    I converted (sort of) the motion math spring script to an expression. This is one of those simulations where at each frame the expression has to go through all previous frames to figure out what state it’s in now, so the render will bog down if your comp is very long. The expression assumes that the layer that it’s following is named “leader”. Adjust the rest length of the spring and the damping factor as needed.

    
    restLength = 20; //rest length (pixels)
    damp = .95;
    leader = thisComp.layer("leader");
    
    fDur = thisComp.frameDuration;
    currFrame = Math.round(time/fDur);
    
    p2 = position.valueAtTime(0);
    v2 = 0;
    for (f = 0; f <= currFrame; f++){
      t  = f*fDur;
      p1 = leader.position.valueAtTime(t);
      delta = p2 - p1;
      nDelta = normalize(delta);
      a = 2*nDelta*(length(delta) - restLength)*fDur;
      v2 = (v2 - a)*damp;
      p2 += v2;
    }
    p2
    
    

    Dan

    Mike Clasby replied 19 years ago 2 Members · 1 Reply
  • 1 Reply
  • Mike Clasby

    April 9, 2005 at 7:45 am

    I think a Fig just hit Newton on the head, especially when the damp is greater than 1, say 1.05.

    For every Action there is a greater, and greater, and greater… reaction.

    I like it.

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