Activity › Forums › Adobe After Effects Expressions › Expression for linking 2 of 3 (X,Y,Z). I need to link Y and Z but not X.
-
Expression for linking 2 of 3 (X,Y,Z). I need to link Y and Z but not X.
Posted by Jason Moore on March 9, 2011 at 2:14 pmFirst off, I know if you’re an expression guru, this is probably super easy. I barely use expressions, and I’m about as right brained as they come.
What I’m trying to do is create a shadow for a 3D model (using a masked solid) that stays on the z plane. So when I move it around from side to side it moves with the object, but not when I move it up (away from the plane).
I think an expression will do this.
I’ve tried searching, but I don’t know what to search for.
Thanks!
JasonJason Moore
Midnight Oil Productions
http://www.midnightoilproductions.comSara Jean replied 11 years, 1 month ago 3 Members · 13 Replies -
13 Replies
-
Kevin Camp
March 9, 2011 at 3:27 pmthis will do what you are asking for (link y and z, but leave x alone):
target = thisComp.layer('3d object'); // this should be your layer to track x = value[0]; y = target.position[1]; z = target.position[2]; [x,y,z]but if you shadow is on the ground/floor plane, then i think you might want it to move on the xz plane so, y would remain constant, like this:
target = thisComp.layer('3d object'); // this should be your layer to track x = target.position[0]; y = value[1]; z = target.position[2]; [x,y,z]Kevin Camp
Senior Designer
KCPQ, KMYQ & KRCW -
Jason Moore
March 9, 2011 at 3:34 pmThanks Kevin,
You’re correct. I had my Xes, Ys and Zs mixed up. I’m going to hold on to this expression. I think I’ll be using this technique a lot.
I ended up separating the X, Y, Z. dimensions and linking just the X and Z. The expression is nicer for sure and I’ll be trying that on the next one.
I appreciate it!
JasonJason Moore
Midnight Oil Productions
http://www.midnightoilproductions.com -
Kevin Camp
March 9, 2011 at 3:49 pmif you want to make it easy to re-use, you can add a layer selector effect (from the expression controls effects) to the shadow layer, then point the expression to the layer selector (leave the selector set at default for now), so the expression would look like this:
target = effect("Layer Control")("Layer"); x = target.position[0]; y = value[1]; z = target.position[2]; [x,y,z]then select the layer control effect and the position property and choose animation>save animation preset and save it.
then when you need it you can apply it from the animation presets and then just use the layer sector to choose which layer the shadow should track.
Kevin Camp
Senior Designer
KCPQ, KMYQ & KRCW -
Jason Moore
March 9, 2011 at 4:05 pmOk… so since you in the helping mode. 🙂
Any ideas on how to make an expression that would make the shadow blur and fade the further up in Y space the object is is? In other words, when the object is not close to the floor, I’d like the shadow to blur and the opacity to fade. If that’s too much to ask, I understand.
What I have is a 3D fountain pen that is writing out some text. I created a shadow using a black solid (in the shape of the pen. A little radial blur and some soft subtract masks have done the trick. I figured I’d hand animate those fade properties, but an expression would save me some work.
I really wish I was more left brained and could grasp expressions better.
Thanks!
JasonJason Moore
Midnight Oil Productions
http://www.midnightoilproductions.com -
Kevin Camp
March 9, 2011 at 4:34 pmif you’re using the layer selector, the expressions could be like this (if not, just change the ‘target’ to be your pen layer):
opacity:
target = effect("Layer Control")("Layer"); maxO = 100; minO = 0; maxD = 300; minD = 0; d = length(position,target.position); linear(d,minD,maxD,maxO,minO)blur amount:
target = effect("Layer Control")("Layer"); maxB = 50; minB = 0; maxD = 300; minD = 0; d = length(position,target.position); linear(d,minD,maxD,minB,maxB)just set the min/max ranges for each to suit…
if needed, you could use a similar expression on any mask feather property too.
Kevin Camp
Senior Designer
KCPQ, KMYQ & KRCW -
Jason Moore
March 11, 2011 at 4:50 pmAwesome! I didn’t get a notification email for this yesterday. Thanks so much for taking the time to do this!
Jason
Jason Moore
Midnight Oil Productions
http://www.midnightoilproductions.com -
Jason Moore
March 11, 2011 at 5:38 pmKevin,
I went back and set up my comp using the first expression and a layer control effect. It works perfectly.
I’m such an expressions idiot, I’m having trouble applying the opacity expression after that. I keep getting errors.
Am I just supposed to paste in:
target = effect(“Layer Control”)(“Layer”);
maxO = 100;
minO = 0;
maxD = 300;
minD = 0;
d = length(position,target.position);
linear(d,minD,maxD,maxO,minO)
after this:
target = effect(“Layer Control”)(“Layer”);
x = target.position[0];
y = value[1];
z = target.position[2];
[x,y,z]Or do I need to plug in some numbers first? This is the error I’m getting.
After Effects warning: Expected: ;
Expression disabled.Error occurred at line 5.
Comp: ‘PEN’
Layer: 8 (‘Dark Gray Solid 5’)
Property: ‘Position’This is probably terribly simple. I just don’t know much about working with expressions.
I really appreciate the help you’ve offered so far.
Jason Moore
Midnight Oil Productions
http://www.midnightoilproductions.com -
Jason Moore
March 11, 2011 at 5:50 pmOk… scratch that. When I paste in the opacity expression first I don’t get any errors.
I’ve played around with the max and minimum value, but I wasn’t getting anything.
Right now my Y value is 359.8. That’s touching the “paper”. At about 325, I want the shadow to be completely transparent and blurred.
I don’t understand the expression well enough to know what to change.
Again, I very much appreciate your help. And if you’ve had enough, I completely understand.
Jason
Jason Moore
Midnight Oil Productions
http://www.midnightoilproductions.com -
Kevin Camp
March 11, 2011 at 10:16 pmhi jason,
first off, the opacity expression should be pasted into the opacity property expression field for the shadow (select the opacity property and choose animation>add expression and paste into that field that shows up in the timeline).
now, to breakdown the expression (it’s not as intuitive as i’d like):
target = effect(“Layer Control”)(“Layer”); // this line just sets the other layer (pen layer) to use for referencing.
maxO = 100; // this is the maximum opacity value, if you never want the opacity to be greater than 50, then set that to 50…
minO = 0; // this is the minimum opacity value, again if you never wanted it to get less than 10, then set that to 10…
maxD = 300; // this is the max distance threshold that is measured between the shadow layer and the target (pen) layer.
minD = 0; // this is the min distance threshold between the 2 layers.
d = length(position,target.position); // this calculates the distance between the layer and the target layer.
linear(d,minD,maxD,maxO,minO) // and this basically converts distance values to opacity values based on the parameters that were set above.
hopefully this helps a bit. let me know if there are any other questions.
Kevin Camp
Senior Designer
KCPQ, KMYQ & KRCW -
Jason Moore
March 11, 2011 at 10:33 pmYou are a saint man.
I’m a little embarrassed that I didn’t think about the fact that the opacity should be pasted in the opacity property. I’m low on expression knowledge, but that was just dumb.
I’ll see if I can get this to work.
I really, really appreciate this. You’ve helped me a ton.
Thanks!
JasonJason Moore
Midnight Oil Productions
http://www.midnightoilproductions.com
Reply to this Discussion! Login or Sign Up