Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions CLAMP or LINEAR to limit scale?

  • CLAMP or LINEAR to limit scale?

    Posted by David Rodriguez on June 24, 2008 at 10:30 am

    temp = thisComp.layer(“UPDOWN”).transform.position[1];
    [temp, temp]

    I am using the above expression on the scale property of an object to tie it to the vertical movement of another layer. What I need is to limit the horizontal scale of the object between 65% and 100% and the vertical scale of the object between 75% and 100%
    I did some searching around and the best I can figure is that I need to use CLAMP or LINEAR. I do not know which I need and how to insert it into the existing expression. I’m a little lost here.

    Any help is much appreciated.
    David

    Filip Vandueren replied 17 years, 10 months ago 2 Members · 6 Replies
  • 6 Replies
  • David Rodriguez

    June 24, 2008 at 11:05 am

    I have it working with x,y together.

    temp = thisComp.layer(“BOTTLE 2”).transform.position[1];
    result = linear(temp, 150, 280, 75, 100);

    [result,result]

    I am so bad at this stuff, my apologies for being a dufus but how do I make this work for x and y separately?

  • Filip Vandueren

    June 24, 2008 at 11:24 am

    Hi David, position and scale are 2- (or 3-) dimensional properties. They have an x and a y component.
    Motionscript uses an Array syntax or a list to assign those numbers.
    For example: [100,50]
    You can retrieve one component from a property by using it’s index: x=0, y=1 like this:

    x = position[0];
    y = position[1];

    since the linear() method likes to work with numbers, not lists/arrays, we apply the linear to x and y separately, then put the result back in a 2-dimensional array (because scale will give an error if it only gets a number as a result of the expression):


    x_temp = thisComp.layer("UPDOWN").transform.position[0];
    y_temp = thisComp.layer("UPDOWN").transform.position[1];

    x_result = linear(x_temp, 150, 280, 65, 100);
    y_result = linear(y_temp, 150, 280, 75, 100);

    [x_result, y_result] ;

    I hope that makes sense. You’ll have to tweak the numbers in that linear expressions probably.

  • David Rodriguez

    June 24, 2008 at 11:36 am

    Thanks!

    So if I wanted both X and Y scale to be affected differently by the vertical motion of another layer I could use

    x = position[1];
    y = position[1];

    x_temp = thisComp.layer(“UPDOWN”).transform.position[1];
    y_temp = thisComp.layer(“UPDOWN”).transform.position[1];

    x_result = linear(x_temp, 150, 280, 65, 100);
    y_result = linear(y_temp, 150, 280, 75, 100);

    [x_result, y_result] ;

    ?

  • Filip Vandueren

    June 24, 2008 at 12:22 pm

    yes, though you only need to “sample” the vertical motion once: you can/should use the same variable in two different formulas.
    Also the first two lines have no use here: you’re defining x and y as the componenets of this layer’s position, then you don’t use it in the rest of the expression.
    So your code works, but could be simplified like this:


    y_temp = thisComp.layer("UPDOWN").transform.position[1];

    x_result = linear(y_temp, 150, 280, 65, 100);
    y_result = linear(y_temp, 150, 280, 75, 100);

    [x_result, y_result] ;

    notice I used y_temp in both formulae.

  • David Rodriguez

    June 24, 2008 at 1:29 pm

    I understand. Thank you!
    So I could use the following for an independent X,Y scale expression based on the X position of a layer called “UPDOWN”

    wichita = thisComp.layer(“UPDOWN”).transform.position[0];

    x_boogedy = linear(wichita, 150, 280, 65, 100);
    y_boogedy = linear(wichita, 150, 280, 75, 100);

    [x_boogedy, y_boogedy] ;

  • Filip Vandueren

    June 24, 2008 at 6:40 pm

    Correct

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy