ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Clamp position by comp percentage?

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Kieran Lefort
Clamp position by comp percentage?
on Oct 9, 2019 at 11:12:03 am
Last Edited By Kieran Lefort on Oct 9, 2019 at 11:13:29 am

I swear I've seen this somewhere, but I'll be damned if I know what to Google.

Let's say there's a 2D layer I want to be able to put anywhere in my comp, but at no point can it enter the top 10% of the screen. How would I write that as an expression?

EDIT: Or could I even have an invisible layer as blocker and write an expression to prevent the two interacting?


Return to posts index

Andrei Popa
Re: Clamp position by comp percentage?
on Oct 11, 2019 at 8:09:07 am

You mean that the vertical position can not go in the top 10% of the comp?
Try this:

minValue = height*0.1;

(value[1] < minValue) ? value : [value[0], minValue]


or


yPos = Math.max(height*0.1, value[1]);
[value[0], yPos]


Andrei
My Envato portfolio.


Return to posts index

Kieran Lefort
Re: Clamp position by comp percentage?
on Oct 11, 2019 at 4:24:12 pm

Hi Andrei,

Thank you for that. I'm a little confused about the first one. I'm still quite new to expressions and haven't come across "?" before. What does it do?

The second version worked quite well. I'm wondering if there's a way to incorporate the layer's scale into it somehow.

This might be hard to explain, but I'm going to try. Unfortunately, I can't share screenshots or snippets because, y'know, NDAs and all that.

Layer A sits in the top 10% of my comp and Layer B is not allowed to touch it, BUT the upper edge of Layer A is allowed to get as close as possible. I hope this makes sense so far.

Layer B, for other reasons, has to scale from the bottom, so the location of its upper edge changes, but that upper edge still needs to be able to get as close to Layer A as possible without touching it.

Is there a way to essentially say "as the scale decreases, the object is allowed to get closer"?

Another way to explain it might be this...

Lay your hand, palm up, on your desk and touch the bottom edge of your keyboard with your finger tips. Now curl your fingers in and slide your hand up until your knuckles touch the keyboard. This is effectively what Layer B needs to be able to do.

My brain hurts just thinking about this. 😄


Return to posts index


Andrei Popa
Re: Clamp position by comp percentage?
on Oct 11, 2019 at 6:40:59 pm

The first one is a "ternary" operator. Check this page for some info.

I don't really understand what you are after here. You have Layer A that sits on top. Layer B can increase in scale until touching Layer A, without any overlay. With this behavior in mind, you want to modify the position of the Layer B so it moves down if the scale is too big or do you want to make this a max size and the layer can not increase further?

And what conditions does Layer A have? Only that it has to stay in the top 10 %? Can you make a really simple animation/picture using two rectangles as layers?

Andrei
My Envato portfolio.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]