Activity › Forums › Adobe After Effects › Expression to move Z position
-
Expression to move Z position
Posted by Heath Robinson on August 3, 2007 at 3:48 pmI just watch the After Effects podcast explaining the Linear function, i wanted to see if i could use the expression to move text in z space to bounce with the audio keyframes i have, i have the ranges of each function all set up. i just need to know how to get it to apply to only z space?
Here is the expression i have:
x=thisComp.layer(“Audio Amplitude”).effect(“Both Channels”)(“Slider”);
linear(x,0,100,-138.2,-180) where -138.2 and -180 is my range in z space. Anyone know how to make this work correctly, i am (obviously) new to expressions.THANKS ALL!
HeathDavid Franklin replied 18 years, 9 months ago 3 Members · 8 Replies -
8 Replies
-
David Franklin
August 3, 2007 at 4:34 pmI think I’m supposed to tell you to post this in the expressions forum. But now that I have, let me try to answer.
The key is understanding that the 3D position of any layer is an array of three numbers which can be expressed as:
[x,y,z];
Where x is the x coordinate, y is the y coordinate, and z is your z coordinate. So if you want to take what you wrote, and apply it to an object living in a 720×540 comp, you’d simply copy the expression you already wrote, alt-click the stopwatch of the position perameter of your layer, and paste your expression, followed by a semicolon.
On the next line, you’d just write [360,270,x];
It might be less confusing if you used “z” as your variable instead of “x”, as it would then be clear that this is going into z space.
But it will work either way.
Oh, and if you want to change the x and y positions, go ahead, I just defaulted to having it in the middle of the screen.
Good luck…
-
Mike Clasby
August 3, 2007 at 6:53 pmThis will work for you.
x=thisComp.layer(“Audio Amplitude”).effect(“Both Channels”)(“Slider”);
zBounce = linear(x,0,100,-138.2,-180);
[position[0],position[1],zBounce]But changing the x to something else might be clearer to others seeing your expression.
amp = thisComp.layer(“Audio Amplitude”).effect(“Both Channels”)(“Slider”);
zBounce = linear(amp,0,100,-138.2,-180);
[position[0],position[1],zBounce]Explanation
position[0] just tells it to use the original x
position[1] the original y
and then to use “zBounce” as the z -
Heath Robinson
August 3, 2007 at 6:56 pmi put in the function and it works but now it moving toward the center of the cube (ie back towards zero) and if i delete the linear function (Line 2 in the function below) then it still operates, is there any way to set permeters to where it would bounce outward:
z=thisComp.layer(“Audio Amplitude”).effect(“Both Channels”)(“Slider”)-138.2;
linear(z,0,100, -138.2,-150);
[352,245,z];i added the -138.2 for the position it needs to come to rest at, i just need to invert the motion.
Thanks for the help so far man, I’m almost there!
Thanks
Heath -
Heath Robinson
August 3, 2007 at 7:00 pmnever mind i got it, i multiplied the parameters by a negative 1. Here is the final code, Thanks for the help “yikesmikes” i guess algebra came in useful after all.
Here is the final code for reference:
z=thisComp.layer(“Audio Amplitude”).effect(“Both Channels”)(“Slider”)*-1-138.2;
linear(z,0,100, -138.2,-150);
[352,245,z]; -
Mike Clasby
August 3, 2007 at 7:49 pmYour second line,
linear(z,0,100, -138.2,-150);
is not really doing anything, it’s interpolation is not being used later. With the “-138.2” added to the first line you did your interpolation there, sort of. You can delete line 2 in your expression and nothing will change. Drop the “-138.2” in line 1, make the second line equal to something, I believe it’s called a variable, then drop that into your bottom line, like this.
z=thisComp.layer(“Audio Amplitude”).effect(“Both Channels”)(“Slider”);
a = linear(z,0,100, -138.2,-150);
[352,245,a]Also, look at the values that the Audio Amplitude layer is producing, twirl down to see the curve, it probablyt doesn’t go from 0 to 100 (the slider value) but maybe something like 0 to 35 or 40. You can change line 2 (the linear interpolation) from 0-100 to 0-40(or35, whatever):
a = linear(z,0,40, -138.2,-150);
Also I noticed you changed the interpolation from you first post, it was:
linear(x,0,100,-138.2,-180)
and is now
linear(z,0,100, -138.2,-150);
I’m assuming you now only want a 11.8 pixel bounce when originally you wantd a 41.8 pixel bounce.
It might be easier to setup the ranges as variables, like this, so you can see the maximums and minimums you’re using:minAudio = 0 // the lowest audio amplitude;
maxAudio = 40 // the highest audio amplitude;
minZ = -138.2 // minimum Z bounce;
maxZ = -180 // maximum Z bounce;
z = thisComp.layer(“Audio Amplitude”).effect(“Both Channels”)(“Slider”);
a = linear(z, minAudio, maxAudio, minZ, maxZ);
[352,245,a]
Or maybe not.Dan is a great source for expressions, here:
https://www.motionscript.com/mastering-expressions/language-beginning-2.html
His site is wondrous, here:
-
Heath Robinson
August 3, 2007 at 7:57 pmThanks so much, i got it working but i think i will need to put a little more explanation into whats going on, because i know i’ll use this expression in future projects.
Thanks for the references as well it’s added to my bookmarks.
Have a magnanimous weekend!
Heath -
Mike Clasby
August 3, 2007 at 7:59 pmHey, I’ve probably already said to much, I’m glad your method worked.
-
David Franklin
August 3, 2007 at 8:34 pmYikes indeed! I just reread everything and saw that Yikesmikes is right, you didn’t have a second variable in your initial expression. Not sure how I missed that. But on second read, my suggestion that “it would be less confusing” sounds like gibberish!
But certainly, you need first to link to the slider info (that would be the first variable, what you were calling “x” in your initial post). Then you need to do the linear function on that value “x”. Then you need a second variable, which Yikesmikes suggests calling “zBounce” to pick up the output of the linear function so that you can stick it into your position expression.
And of course, Yikesmike’s solution of [Position[0],Position[1],zBounce]; is ever so much more elegant than just plugging in the raw position coordinates as I suggested.
Still, glad you got it working to your satisfaction…
Reply to this Discussion! Login or Sign Up