Hi there!
I'm trying to write an expression that will scale a layer up/down as another layer gets closer (simulating a UI element jumping off the page as a mouse cursor hovers over it). This is what I've got so far (expression applied to the scale property of the target layer):
x = Math.abs((effect("Mouse Layer")(1)).transform.position[0] - transform.position[0]); // distance between target layer and mouse on x-axis
y = Math.abs((effect("Mouse Layer")(1)).transform.position[1] - transform.position[1]); // distance between target layer and mouse on y-axis
t = Math.sqrt((Math.pow(x,2)) + (Math.pow(y,2))); // actual distance from mouse layer to center of target layer
fadeDist = effect("Fade Dist")(1); // distance at which layer begins scaling
sMin = effect("sMin")(1); // scale minimum
sMax = effect("sMax")(1); // scale maximum
s = ease(t, 0, fadeDist, sMax, sMin);
[s,s];
It works fairly well, but it's based on the distance between the center of the target layer and the mouse, not the boundaries/edges of it. Because of this, the target layer's scale changes while the mouse is moving around within the area of the layer itself.
Is there a way for me to write this expression that will 1) allow me to reference the distance between the mouse and the edges of the target layer (a rectangle) as the factor affecting the layer's scale, and 2) maintain the scale of the rectangle while the mouse moves around within it?
Thanks!!