Distance between two points to drive scale of object series
- January 4, 2024
- 1 reply
- 469 views
I am trying to make a series of rectangles scale up and down on the y-axis. Each rectangle scales based on its proximity to a null controller. This video explains the expression I'm using to drive the y-scale.
When the first rectange (leader) scales up, the neighboring rectangle (follower) changes position based on leader's scale. However, when the controller approaches the follower, no scale change occurs. The controller does affect the follower's scale when at the top of the comp. My question is: why does the controller not affect the follower's scale at the appropriate position? Additionally, how can I have a series of rectangles each respond to the controller (for scale) and their neighbors (for position)?
Here is the code I'm using to drive the scale of the leader and follower:
var p1 = transform.position;
var p2 = thisComp.layer("Controller").transform.position;
var ScaleFrom = thisComp.layer("Sliders").effect("ScaleFrom")("Slider");
var ScaleTo = thisComp.layer("Sliders").effect("ScaleTo")("Slider");
var HitIn = thisComp.layer("Sliders").effect("HitIn")("Slider");
var HitOut = thisComp.layer("Sliders").effect("HitOut")("Slider");
var d = length(p1,p2);
var r = linear(d,HitOut,HitIn,ScaleFrom,ScaleTo);
var x = 100;
[x,r]
Here is the code I'm using to drive the position of the follower:
//variables for leader
var lead = thisComp.layer(index+1).sourceRectAtTime();
var leadyp = thisComp.layer(index+1).transform.position[1];
var leadsy = thisComp.layer(index+1).transform.scale[1];
var h = (lead.height*leadsy)/100;
//variables for follower
var follow = thisLayer.sourceRectAtTime();
var followypos = transform.position[1];
var followysca = transform.scale[1];
var ha = (follow.height*followysca)/100;
//Below are the calculations
var offy = h/2+ha/2;
y = offy + leadyp;
[1920,y]
I've included labeled screenshots of the project I'm referring to. I've also included the project file itself. Any help would be greatly appreciated! Thanks!
