Activity › Forums › Adobe After Effects Expressions › Using “clamp” in a wiggle expression to limit
-
Using “clamp” in a wiggle expression to limit
Posted by Riccardo Sinti on June 17, 2005 at 3:40 pmSo now I have this expression on Postition
[position.wiggle(5,40)[0], position.wiggle(5,40)[1]]
Where do I add the Clamp(value, limit1, limit2) to the above expression?
I want to limit the y wiggle to a “floor” so that my layer wiggles side to side and up and down but not below a certain level.Expressions are fun but very daunting.
Dan Ebberts replied 19 years, 7 months ago 2 Members · 9 Replies -
9 Replies
-
Dan Ebberts
June 17, 2005 at 3:56 pmDo you want it to just sit on the “floor” until the wiggle goes above that value, or do you want some other behavior?
Dan
-
Riccardo Sinti
June 17, 2005 at 4:06 pmWell, my layer is a “box” resting on a “surface” and needs to shake and jitter.
It should bounce around in all directions but obviously, and to make it look more realistic, it shouldn’t drop below the “floor” or the “surface”
How do I limit the lower range of the the wiggle to a “floor” value?
thanks -
Dan Ebberts
June 17, 2005 at 4:12 pmHere are two different ways:
w1 = wiggle(5,40) – value;
w2 = clamp(w1,[-40,-40],[40,0])
value + w2w = wiggle(5,40) – value;
value + [w[0],-Math.abs(w[1])]Either expression will keep the object from moving below its starting point. The first one clamps downward movement, the second one reflects it upward.
Dan
-
Riccardo Sinti
June 17, 2005 at 4:54 pmThanks alot, this works very well.
If you have the time could you parse these expressions for me so as to explain what each section does?For this expression:
w1 = wiggle(5,40) – value;
w2 = clamp(w1,[-40,-40],[40,0])
value + w2My understanding is that the first two lines you are setting up variables.
What is “value”.So w1 establishes the wiggle?
and w2 establishes the clamp? the first part of the Clamp array is w1 establishing the value of the clamp
and then the second is the lower limit in x,y (if it were a 3D layer we would need x,y,z, correct?)
and then the upper limit
I dont understand the third line or how exactely the “floor” has been established.this expression:
w = wiggle(5,40) – value;
value + [w[0],-Math.abs(w[1])starts like the first one but the second line is perplexing.
I would also love to link another layer, a shadow layer made with masks, to react to the wiggle of the “box” layer so that it shifts in x position with the box and also the mask expands and feathers the further away from the floor the box is.
Am I only dreaming?thanks so much
-
Dan Ebberts
June 17, 2005 at 5:51 pmSure,
w1 = wiggle(5,40) – value;
w2 = clamp(w1,[-40,-40],[40,0])
value + w2The first line is used to isolate the wiggle from the property’s (Position in this case) value. For example, if you have an object located at [100,100],
wiggle(5,40)
will give you values that range from [60,60] to [140,140]. These values are centered around [100,100]. By subtracing “value” (which is just shorthand for “the pre-expression value of this property” = the same as “position” in this case), you isolate the wiggle component and the result ranges between [-40,-40] and [40,40] (centered around [0,0]), which is what we need for the next step. The clamp function just clamps the first parameter so that it lies between the second an third parameters. In this case, it’g going to clamp our wiggle value between [-40,-40] and [40,0]. So what we have done here is replace all positive y values (which represents downward movement in the AE coordinate system) with 0’s.
value + w2
just adds the clamped wiggle component back onto the non-expression position value.
In the second expression:
w = wiggle(5,40) – value;
value + [w[0],-Math.abs(w[1])We’re again isolating the wiggle component. The -Math.abs(w[1]) just ensures that any positive y wiggle value gets converted to a negative value (negative values will remain negative). This just reflects any downward wiggle to upward wiggle.
You’re correct that if it were 3D we’d have to deal with x,y, and z.
Assuming your wiggling layer is named “Layer 1” these expressions for your shadow layer should get you headed in the right direction:
// mask expansion
minExpansion = 0;
maxExpansion = 25;layer1RestPos = [320,240];
delta = thisComp.layer(“Layer 1”).position – layer1RestPos;
linear(delta[1],-40,0,maxExpansion,minExpansion);// mask feather
minFeather = 0;
maxFeather = 25;layer1RestPos = [320,240];
delta = thisComp.layer(“Layer 1”).position – layer1RestPos;
f = linear(delta[1],-40,0,maxFeather,minFeather);
[f,f]//position
layer1RestPos = [320,240];
delta = thisComp.layer(“Layer 1”).position – layer1RestPos;
value + delta[0]Dan
-
Dan Ebberts
June 17, 2005 at 6:14 pmOh yeah, you’ll have to edit the last three expressions so that “layer1RestPos” represents Layer 1’s rest position. If Layer 1 is keyframed we have more work to do 🙂
Dan
-
Riccardo Sinti
June 17, 2005 at 7:06 pmSo my “box” layer starts off still on the “floor” I used a slider control and pick-whipped the wiggle amplitude to the slider and key framed the slider from 0 to 15 which is about how far I wanted it to wiggle. Will this have any bearing on the values in the Clamp array (is that the right terminology)?
My starting box poisition, before the expression is (342,262). Does that have and bearing on the
layer1RestPos = [320,240]
in the feather expression you gave me.
Should I insert my layer’s initial position?You are schooling me greatly.
Did you learn all this Java script using AE Expressions or did you program prior to AE Expressions?
Thanks -
Riccardo Sinti
June 17, 2005 at 7:07 pmOh I see you just added to the previous post which answered part of my follow up.
Makes sense! -
Dan Ebberts
June 17, 2005 at 8:25 pm>and key framed the slider from 0 to 15 which is about how far I wanted it to wiggle.
>Will this have any bearing on the values in the Clamp array (is that the right terminology)?That probably means you should replace all the 40’s with 15’s
>Did you learn all this Java script using AE Expressions or did you program prior to AE Expressions?
Yes and yes. 🙂 I had never touched JavaScript before expressions but I’ve been writing code for a long time.
Dan
Reply to this Discussion! Login or Sign Up