ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Position A = 0%, Position B = 100%

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Ryan Hauser
Position A = 0%, Position B = 100%
on Feb 9, 2017 at 1:36:53 am


I'm wondering if there's any way, with expressions, to set something's position based on a percent.

Here's an example pseudo code for what I'm looking for :
Position 0% = 0,0;
Position 100% = 100,100;

The reason is that I am creating a rig for an eye. I want the eye to open and close (using square solids to block the eye), but I also want to be able to change the "line" where the eye is 100% closed. This way I can have the eyes look closed, bored, sleepy, scared, excited, etc. I can't just use a single null to control the eyelids, as the bottom eyelid and the top eyelid would "enter frame" at different times if the "100% closed" position wasn't located directly in the center. I would want them both to start from the bottom/top at the same time, regardless of where the "100% closed" line is.

Essentially, the pseudo code of the expression I need looks something like this. I would put this on the top and bottom eyelids, but with varied starting positions:
Position 0% = 50,-50;
Position 100% = thisComp.layer("center").transform.position;

I would then use a slider to control the percentage completion, so I could control blinking with keyframes.

Something else to note - if at all possible, I don't want to use any extra precomps.


Return to posts index

Emre Anil
Re: Position A = 0%, Position B = 100%
on Feb 9, 2017 at 8:09:13 am

I did something similar to this before:

The idea there is the same but it can also go beyond the weight limit. Keep in mind that I used 0-1 as weight not 0-100

Here's the script part for you:
Adjust p1 and p2 values for your target's positions

w = effect("weight")("Slider");
p1 = thisComp.layer("P1").transform.position;
p2 = thisComp.layer("P2").transform.position;
x = ((1 - w) * p1[0]) + (w * p2[0]);
y = ((1 - w) * p1[1]) + (w * p2[1]);
[x, y];

Return to posts index

Kevin Camp
Re: Position A = 0%, Position B = 100%
on Feb 9, 2017 at 5:16:05 pm

just to show you other options that can do the same...

I often use the linear() function to interpolate between dissimilar values (like percentage and position, or position and rotation, etc..). a basic set up using linear() could look like this:

completion = effect('slider control')('slider');
closed = thisComp.layer("center").transform.position;
open = [ 50, -50 ];
linear( completion, 0, 100, open, closed )

also, not that you need to change your set up, but the cc jaws effect might make things a little simpler to create our eye lids... by default the jaws effect will create cheesy teeth, but if you set the height to 0, it will create a simple wipe that starts at a point and wipes outward. that point could be linked to you 'center' layer's position and then use the completion setting (0-100) within the effect to open and close both the top and bottom eye lids. it may not work for exactly how you want things to be, but the functionality seems close, so i thought i'd mention it.

Kevin Camp
Art Director

Return to posts index

Ryan Hauser
Re: Position A = 0%, Position B = 100%
on Feb 9, 2017 at 6:32:24 pm

Thank you, guys. It works perfectly!

Also, I didn't know about CC Jaws. While it doesn't quite do what the expression you listed accomplishes, it's a truly glorious effect!

Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 All Rights Reserved