4 Replies Latest reply on Dec 2, 2009 3:20 PM by Andy Bay

# Simple expression maths question

Hi!

I really regret skipping so many math lessons in highschool, because with AE using math is actually fun and usefull :S

The thing is quite simple:

I have two layers, let's call them 1 & 2.

Layer 1 needs to take it's opacity animation from Layer two. So far so easy, just use the expression pickwhip.

But here's where the issue is that my slow brains can't seem to figure out:

The starting opacity of Layer 2 is not 100% but instead 40%. However, for layer 2 the starting opacity is 100%. If I simply pickwhip the opacity, then layer 1 is going to jump it's opacity to 40% which is not good. So I tried an if/else statement like this for layer 1:

opa=thisComp.layer("Shape Layer 1").transform.opacity+60 //adding 60 to make the opacity of layer 1 start correctly at 100

if (opa<100) opa else (value) //tell layer 1 to follow the opacity of Layer 2 only when it starts dropping below 100

However, this of course results in the opacity of layer 1 stopping at 40%.

I know the solution to this must be embarrasingly simple. But how on earth do I make the Layer 1 start at 100% opacity and drop to 0% opacity when the Layer 2 which is the master layer is starting at 40% and ending to 0%?

Most of all I would like to know how I should approach this correctly, like what is the mathematical way to solve this simple equation? You know the saying about teaching a man to fish right?

• ###### 1. Re: Simple expression maths question

Fortunately, this is simple.

You need the ability to map a range of values proportionally into another range of values.

The most common range mapping methods in AE expressions are linear() and ease().

So, you would use something like this in Layer 2's opacity.

range = thisComp.layer("Layer 1").transform.opacity;

linear(range, 100, 0, 40, 0);

Obviously, "range" is a variable. It stores the value of layer 1's opacity.

And the linear method works as if it was saying "as range goes from 100 to 0, convert the range proprtionally to 40-0".

I hope it's clear.

• ###### 2. Re: Simple expression maths question

Thank you very much, that certainly works!

I was just thinking that could it be possible to solve this also by multiplying/dividing the values in some manner? Or is it impossible to solve a problem like this with just basic maths?

• ###### 3. Re: Simple expression maths question

Of course you can do this by multiplying.

L1 = 40 .... 0

L2 = 100 ...0

Layer 2's opacity = (100/40) x Layer1Opacity.

Your problem was you were trying to add, when you needed to multiply....