Skip to main content
Nelson_L
Participant
January 4, 2024
Question

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!

This topic has been closed for replies.

1 reply

Dan Ebberts
Community Expert
Community Expert
January 4, 2024

I'm not sure, but my guess is that you have expressions that are fighting each other. As the controller approaches the follower, the scale expression wants to increase its size, which makes the position expression try to move it away to maintain its position relative to the leader, which causes the scale expression to want to decrease its size, etc. That kind of loop generally leads to an unpredictable result.

Nelson_L
Nelson_LAuthor
Participant
January 29, 2024

Yep that was the issue. I needed to add the leader variables to the scale expression as well. Otherwise the scale would get all wonky. Here's what I found worked for me:

For the position:

//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]

 

For the scale:

//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;

var p1 = [1920,y];
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 = ease(d,HitOut,HitIn,ScaleFrom,ScaleTo);
var x = 100;
[x,r]

 

Thanks for your help Dan!