-
derekd – here’s your spring expression
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