Forums › Adobe After Effects Expressions › derekd – here’s your spring expression
-
derekd – here’s your spring expression
-
Dan Ebberts
April 8, 2005 at 5:58 pmI 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
April 9, 2005 at 7:45 amI 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.
Viewing 1 - 2 of 2 posts
Log in to reply.