16 Useful Expressions in After Effects - Part 1 of 2

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome to Yuka Mediacom my name is Sergey prac Nevsky and today I'm going to show you 16 useful expressions in After Effects so without any further ado let's dive right in number 1 is value and is extremely easy but very useful so let me show you what I'm talking about here I'm going to select the first layer here and I'm going to hit our my keyboard to reveal the rotation property and next I'll hold down alt and click on the stopwatch to activate my expression and I'm just going to type in 50 in here what happens as you can see it set my rotation to 50 and it's pretty locked in so I can't really control this number it's locked in to 50 and I can be a bit of a problem so what happens if I want to have control over that so all you do just type in value and what it does is it gives you the current value that you type in in here so you can type in 20 and that's what it'll give you 20 and you know how can that be useful you can definitely build up on that so I can say value times 2 and as you can see my 20 went to 40 if I type in 60 you know give me 120 but the problem is what if you know this is just one dimension but what if you're dealing with something like position I'm going to hit P on my keyboard and you see two dimensions or even yet you know if you make it 3d you have three dimensions how do you deal with that and so that's where you would have to define which value talking about here so the way it works in After Effects you just have to label which value so the first value would be value 0 you would think it would be 1 but it's actually 0 and then this will be valued 1 and then value 2 so let me show you what I'm talking about here I'm going to I'll click on the stopwatch here I'm just going to define each value so I'm going to open square bracket here and just type value and then open square bracket 0 and call the square bracket so I just define the first one and then I'm just a comma and open square bracket 1 and the value open square bracket to close and I'm gonna do another close square bracket to close the whole thing and as you can see that I just define all 3 of them so now I can work with this you know I can say this second value in here whatever I type in and here at times 2 so if I type in a hundred it's going to give me you know 200 so you can see how value can be useful in After Effects number two is layer index and so for as I have two of my logos in here and I'm going to hit P on my keyboard to reveal position property of each logo and I'm going to play with this one first I'm going to I'll click on the position stopwatch and now you can see my expression is active and I'm going to just separate these two X&Y just separate them and I'm going to type the same thing we've done in the previous example so something like this and then close square bracket so as you can see I just separate them in my expression so now I can say all right this first value I'm going to tell you to be X and if I let go and there's an error it doesn't know what X is because I made it up and so now I have to define for after-effects what X means so I'm going to say X you are x equals and then I'm going to say pick whip over here to the x-axis of the layer below position x-axis and next I'm going to do semicolon to close that so it's like a period in expression world and as you can see it snaps right at the same x axis that it is on this layer and so what happens if I add something to this I'm going to say let's do plus 300 and as you can see it offsets it so that's kind of cool but what if let's say I don't want to refer to a specific layer what if I want to refer to a layer below like right now it says you know logo 1 so it strictly refers to this layer but what if I wanted to refer to whatever is underneath it or above it and so that's where index comes in layer index comes in handy so if I type in index and then index is basically this number so 1 2 3 so if I want to refer to the layer below me as you can see the number is 2 so it's a bigger so I'm on 1 so I want to go to index that's a bit bigger to write so it's going to be plus 1 and then you can see nothing happens because it's referred to first to the exact same layer so that's good but where I can get really awesome is when you select this layer and then do ctrl D and duplicate it and now this layer refers to this one and so on you can see how it kind of offsets itself so yeah it can be very useful number three is time and so for this I have just a text and a logo in my composition and so the reason why I have texts basically for like debugging purposes so I can visually show you what I'm talking about so let's say I'm going to all click on this source text and to activate the expression and I can just type in 50 for example and you can visually see 50 so what happens if you do like time times I don't know 40 now you can visually see that the number is moving and so essentially what time is it's almost like an engine so it gives you like a motion or a movement right and so let me show you how you can use that in a practical sense I'm going to select my layer here and hit R to reveal the rotation property and I'm not I'll click to activate the expression and inside here I can i can just say time let's say times I don't know 25 and now visually you can see that it's actually animating my you know my property here so you can definitely see how time can be used in expression number four is value at time and so for this I have four logos but the first logo is actually keyframed and as you can see it's scales in and I just have two keyframes but what happened if I want to apply this animation to all my other layers and I'm just going to select the other non animated layers and hit s to reveal the scale property and so what if I want to apply this animation to that without using keyframes and so I'm just I'll click on the scale property of this layer here and I'm going to pick whip two and refer the animation that's above me so basically now it's grabbing this animation and applies it here without using keyframes but what if let's say I want to do the whole index thing I want to refer to the layer above and not a specific one right now it refers to one layer one but what if I want to do the whole index so let's do that so I'm going to say index and this time we're going up so I want to refer to the layer above so I'm going to say minus one because remember we're on two and a minus one will bring us to one so and nothing happens obviously it's the same thing but what if I'm going to offset it now and that that's where value at time comes in handy so I'm just going to add to this expression I'm going to say period value at time and then open bracket and I'm going to say time - and I'll say point 1 5 and then close bracket and so what happens now if you play it it slightly offsets it and obviously you can control this number you can you know get the exact offset that you want but this is pretty cool so all I have to do now is just right click on the scale and do copy expression and select the other two scales and then do control V to paste that and if I preview it as you can see all those layers are nicely offset number five is source direct at time and so for this I'm going to double click on this icon in here to bring a shape layer into my composition and I'm going to go a bit deep into it until I get the size here and I'm going to select it and hit S on my keyboard twice to solo that and I'll uncheck this proportion icon and next I'll set my y-axis to 20 pixels and then the x-axis I want to be the exact same as my basically the width of it I want to be exact same as my text so how do I do that let me show you how to set that up and so now I'm before I do that actually I'm going to I'll click on a stopwatch here to activate my expression and I'm going to separate these two basically the same thing we've done in previous examples so I'm just going to type values zero and then the value one and so now for the first value I'm actually going to tell it to be x-axis again and make sure you have comma after that okay and then I'm going to define what that X is I'm going to say X you are going to be the layer below okay and I'll build up on that actually because I have to be more specific here so I'm going to say source rect at time and then open bracket close bracket and then period and now I can either say width or height so I'm going to say obviously I want the width and then semicolon to close that and so now if I let go you can see that the width of the shape layer is exactly same as my text layer in here so this is kind of cool because now whatever I type in here you can see that it's adjusting to the width of my text so here's a practical example how to use source rack the time in a real world project so here's the lower third I created using expressions in other words it only activates all the animations using these two keyframes and then it animates out using the other two keyframes so these four keyframes activate everything else that you see but the way I rigged up text in here if you type any other name would it be like Elijah Patrick you can see that the width of it all adjusts without any kind of problems in other words it doesn't even affect the animation so I can hit preview and you can see that animation is playing very smoothly without any problems so you can see how you can use the source rec time to set something dynamic like this and in fact this lower third I will be showing how to create in one of my future tutorials so definitely be sure to check back number 6 is loop in and loop out and so for this I just have a quick simple animation nothing crazy but what if I want to take this animation and make it loop out all the way to the end of my composition here how do I do that using an expression and so the quickest way to do it is I'll click on this stopwatch here and if you go to expression language menu and under property you can select either loop in a loop out I'm going to select the loop out and what it means loop in loop out it just means that if it says loop out it's going to loop after my very last keyframes here so as you can see it set the cycle and it just will be my animation here but nothing is happening before my first keyframe so but if I were to change a loop out to loop in it's going to loop before my first keyframe and then when it plays out the keyframes and it stops at the very last keyframe so that's what it means loop in and loop out and so I'm going to change it back to loop out but let's see what other options we have here so instead of cycle let's change that to ping pong okay and so now if I scroll that you can see that it's gone back and forth it reverses it so that's it you know that's what it means by ping pong but what if we let's say we wanted to play out these keyframes and then whatever want to ping pong only between these two keyframes I want to go back one keyframe and so that's what it means here num keyframes if you type 1 which means that it's going to play out this animation and then it's going to go back one keyframe and it's just going to do this on and on and on so let me show you what I mean let me preview that so you can see it's playing my animation but then it just goes back and forth and you know and if you set it to two you'll see that it's going to go to keyframes back there you go so that's what it means by num keyframes so I'm going to set it back to the default number which is zero and let's see what else we have here there's also one more option called offset and so what that does I'll just play that out to show you what I mean so it plays out the animation and just offsets it number seven is linear and E's and so for this I have a quick little example in here and so what if let's say when I drag this circle up and down what if I wanted forward to in fact the rotation of this logo how would I make that happen using expressions and so let me show you what I mean here I'm going to select this circle hit P to show the position and then select the logo itself and hit R to show the rotation and I'm going to apply the expression to this rotation so I'm going to I'll click on a stopwatch to activate the expression and I'm going to go into an expression language menu here and go up to interpolation and I'll select this linear expression here and right away I have to do some work here so I'm going to this T I'm going to deal with this one first so I'm going to go to the beginning of this expression and hit enter and I'm going to define what that T is so we're going to T equals we're going to grab the a pick web here the the y-axis of this position of this circle and so that's what we can say t you are that and then I'm going to do semicolon here to close it and so now we have to do some work here so what's the minimum number of this that I want so when it's up here which is around 180 I want you know i'm going to type that's gonna be my minimum number so i'm going to do 180 and then the maximum is when i'm down here which is around 900 or so so I'm going to type 900 so when it is 180 I won the rotation because we were in a rotation I want that to be 90 degrees so again so when I'm up here all the way up here I want for the rotation to be 90 and then when I'm all the way down to 900 want the rotation to be negative 90 so like so so now when I drag this up and down you can see that my logo is going with it and again I'm using a linear but you can also use ease and just a difference in interpolation number eight is clamp and so for this I'm back at the same example here but you know when I click and drag my circle and here you can see that it's moving around all over the place what if I wanted to restrict it on both x-axis and y-axis how do I do that and so that's where clamp comes in useful so I'm going to hit P to reveal the position I'm going to right-click in here and do separate dimensions and so now I just have x and y so for the X I just want to keep it at 180 for in other words I don't want to go side to side at all so I just wanted to stay put at 184 so I'm just going to I'll click in here and just type 184 and when you do that it just restricts you to 184 so now if I click and drag it to the side to side you can see that it's not going anywhere so that was easy but for the y axis I wanted to restrict from remember 180 is my minimum and 900 so I don't want to go below 180 or past 900 so how do I restrict it so that's where the clamp comes in very handy so I'm going to alt click on the Y position here and I'm going to start typing clamp and then open bracket and first I have to define what it is I'm going to be restricting so I'm going to pick whip to this Y position so that's the first thing you'll see here and then next I'm going to do comma and then I'll do my minimum number which is 180 and then comma again and then 900 for the maximum and close bracket and so now if I click and drag this circle if I go all the way down here you can see that it stops at 900 but if I push it all the way up it stops at 180 number 9 is to world and to comp and so this one is quite easy but at the same time it can be a bit confusing so let me show you what I'm talking about here so I have a logo in here and I'm going to hit P on my keyboard to see the position of my layer so and the way it works in After Effects the origin is actually up here of your composition so if I hit 0 you can see that that's where the origin is at but let me undo this so now this is the correct opposition world position of my lair but it gets a bit tricky when you start parenting it to the other object so I'm going to do ctrl alt shift why'd you bring a null and I'm just going to randomly place it over here in my composition so watch what happens to my position when I parent my lair to this null you can see that it gives me a different position but it hasn't moved so why is it and the reason why because now instead of CA this object seeing the world origin which is upper left corner here now its origin is this no this parent and so here's I'll show you what I mean so if I know 0 everything out you can see that it goes to the the origin of this no so that can be you know a bit problematic when you try to link things up because this is not a correct world position so let me show you what I mean I'm going to duplicate this layer and make sure that it's not parented to anything and I'm going to hit P to see my opposition so this is the correct world position it's right over the top of it so I'm going to drag it over here so what happens if I all click on the stopwatch here and just link the position to the position of this layer see what happens look it's even though it's the exact same it's in different positions because this one is the correct position and this one is based on the parent so how would I get the correct position or how would i bypass the this parent and get the correct position and so that's where the two world or two comp comes in handy so I'm going to select this this layer in here and then in this expression just pick whip to the this layer that we want get the correct position from and I'm going to type period to world and then open bracket and Anchor Point close bracket and so now you can see that disappeared because it's right over the top of it and here's the correct position even though they're different but they're in the same position so you can see how to world can come in handy and by the way the difference between two world and two comp to comp has to do more with two dimensions but when you make things 3d you definitely want to use two or and in fact to world also works with two dimensions as well number ten is wiggle and this one is quite popular a lot of people use it so for this example I'm going to apply the the wiggle expression to my rotation property but you can apply it to any of them really so I'm going to select the layer here and then hit R to reveal the rotation and I'll click on the stopwatch here to activate the expression and I'm just going to type wiggle and open bracket so the first number is your frequency so I'm just going to do five and second one is amplitude so I'm just going to do like 90 or so and closed bracket and now if I hit preview you can see that it's going to give me random movement number 11 is if/else and that this one is pretty powerful and you can use in so many ways but I'm only going to show you like one little thing here so for this example I just have the logo again and this time I'm going to apply a check box control right on top of my logo and so there it is and I'll label this wiggle and so what I want to do is when I check this wiggle check box I want for the rotation property of this layer to be wiggling in other words I won't forward to apply the wiggle expression and so let me show you how to set that up so I'm going to select this and hit R to reveal my rotation property and I'll click on the stopwatch to activate the expression and so now I'm going to do if else expression so I'm going to say if open bracket and I have to design if what if this checkbox is checked so how do I tell it to be checked so if you do two equal signs and then one that means it's checked so if checkbox is checked and closed bracket so what do I want to do so if it's checked I wanted to do the wiggle just random wiggle expression so whatever number you want to type in in here that's cool but if it's not then you say else else what else I want to be 0 and a semicolon so so basically if the checkbox is checked I wanted to have the wiggle expression and if it's not I just wanted to do anything so right now it's not checked if I hit you know preview nothing happens but if I check the check box you can see that the wiggle expression is applied number twelve is length and so for this I'm going to use this text to show you visually what I'm doing and also a null end an object so we're going to find the distance between these two and so let me show you visually here in this through this text I'm going to alt click on the source text and then we're just going to type a length and then open square bracket and we should say a and B so point A and point B and so nothing obviously would happen because that's useless information so I'm going to define what a and B is so a equals and I'm going to say it's going to be the x axis of this null and semicolon and then I'm going to do B so I'm going to define what B is in other words second point is going to be the x-axis of this logo and then semicolon so essentially what I did here I define the two points and it will find length between those two points so right now if I like go I see visually the number so if I grab the null if I move it on the x-axis you can see that the closer I get to not to the center of the logo which is the origin it will you know you can get this zero but then if I pull to the left I can see the size of this I guess the radius of this logo and so it's around like what 325 so that's going to cool so I'm going to select this useful expression and ctrl C and copy that and I'm just going to all you know get rid of that and the next one I'll do is go to the scale property of this logo and I'll click on that and then paste that expression into here and so next what I'll do I'll define this length differently I'm just going to say L you're going to equal the length expression and so semicolon here to keep going and so now I'm going to apply this length expression to our linear expression that we learned earlier just to show you how powerful this can be so I'm going to say linear and then open square bracket and I'm going to say grab the values from the L the this L expression so at the minimum number will be 0 and the maximum number will be what is it we said what was the radius I think it was 325 and I want that to affect my scale so I want them from 0 to 250 so close square bracket and semicolon but I also want to define this expression as well I want to give it a variable so I'm going to say temp for right now and then the reason why I do that because I want to apply this to both you know to both dimensions here so I'm just going to say open square bracket and temp apply that expression to this one and then temp to that one and so now if I like go if I grab my null here and if I move it on x-axis you can see that it gives us a cool effect here's a practical example how link can be used in the real-world project and so for this I just have the snow but when you move it up and down it triggers all kinds of stuff as you can see the color changes the size of the text changes and also if you notice in the back there's like a blur and transition and all that stuff and all that stuff is triggered by length and linear and so you can seek out how powerful it can be this dynamic effect and by the way this I will show you how to create in one of my future tutorials so definitely stay tuned for that number 13 is math absolute and so for this I have just text in the shape but I'm going to select this text and hit R to reveal the rotation property and I'm going to alt click on a stopwatch to activate the expression and I'm just going to type math that dot abs and open bracket in close bracket and so what it does obviously right now I have an error but what it does if I type in any negative number would it be you know negative 90 it will always give you a positive number and so how would that be useful so for example I'm going to type in wiggle expression I always do like five not let's do 180 and so now if you play it you can see that it gives me both negative numbers and positive numbers so but what if I wanted to restrict this expression only to positive numbers how would I do it first you know let me define this I'm going to say W you're going to be this wiggle expression semicolon and here I'll do math dot abs and open bracket and I'll say you're going to be W which means that wiggle expression and then closed bracket and so now if you notice it it's only in positive direction so that can be very useful another thing you can do you can also say here if you let's say you want the opposite of that you want everything to be negative you can say x negative 1 and so now everything is negative number 14 is math.round and so this one does exactly what it sounds like so I'm going to I'll click on the source text to show you visually what I'm talking about so if I do an expression like time times 20 you can see visually that I have bunch of numbers and it's pretty messy so how do I get rid of all these decimals and just hold on to the big number and that's where math round comes in handy so I'm just going to define this expression I'm going to say see you're you are this expression and so now I'm going to define it here so let's see I'm going to do math dot round and then open bracket and I'm going to say T close bracket so basically I'm saying around this T value which means this expression in other words instead of pasting that in here I just kind of shorten it and so now if I let go of it you can see that it's going to give me 29 15 is random and what it does it just gives you a random number and so let me show you what I'm talking about here I'm going to select the logo here and hit P to reveal the position of this logo and I'm going to right click here and do separate dimensions so now I just have X&Y separate so I'm going to worry about the x position I'm going to I'll click on the stopwatch here and I'm going to type an expression just type random open bracket and let's just do a written random number I'm going to do 600 and so what it'll do it'll give me a random number that will not go higher than 600 so let's see if I scroll you can see that I have random numbers but they do not go higher than 600 so that's kind of cool but you can also do two numbers you can say give me a random number between 100 and 300 and so now you can see that it gives me a number between these two numbers all right so the last one is math minimum and math maximum so for this I already rigged up a quick example in here I just have two columns in here the column B and I can easily move it up and down just different lengths here and so I also have the shape layer in here it's just a shape layer and I already the position 2 X & Y so I'm only going to worry about the X property in here so if I were to alt click on this stopwatch here and Link it up to any of these two you can see that I will automatically snap you know I did it to be so it snaps to a B and it goes with it but what if I wanted for this shape layer to go with the highest column so let's say if I this one went higher I wanted to for this one to go with the highest one how would I set this up so let me show you how easy it is to do it so I'm going to say math dot Max and an Open bracket and then I'll say a and B and close bracket and then I'm going to define above that what a is and what B is so a is going to be column a and then B is going to be column B and it's really as easy as that and so now it's going to take the maximum number between these two so now if I go let's say if I drag this down it's going to stay with the highest one so if I drag that down it's going to stay with this highest and so you can definitely see how useful this would be with like creating graphs and stuff and the same thing applies for minimum so right now it's going with the highest number but if you were to change this max to minimum or mi n and then you can see that it snaps to the lowest number so if this gets lower then it does the same thing but the opposite alright thank you so much for watching this tutorial I hope you found it useful if you would like the project file of this tutorial you can download it at Yuka Mediacom and make sure you like this video share it subscribe to my youtube channel like me on Facebook follow me on Twitter and all that good stuff but until next time my name is Sergei dragonov ski and this is Yuka Mediacom
Info
Channel: ukramedia
Views: 529,073
Rating: undefined out of 5
Keywords: Expressions, Adobe, After Effecs, ukramedia.com, Sergei Prokhnevskiy, motion design, motion graphics, value, time, Layer Index, valueAtTime(), sourceRectAtTime(), loopOut, linear(), ease(), clamp(), toComp, toWorld, length(), in/else, Math.abs(), wiggle(), Math.round(), random(), Math.min, Math.max, tutorial, lesson
Id: gK1Ejt7qND0
Channel Id: undefined
Length: 28min 35sec (1715 seconds)
Published: Tue Nov 01 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.