1 person found this helpful
This is easy to do with an expression. Here's the theory:
Vector math will measure the distance between any two layer's. The default position of the camera is the the negative zoom value. IOW a camera with a 600 pixel zoom value will have a default z position of -600 pixels. The ratio between the camera's zoom value and the distance to any layer will give you the effective scale of that layer.
All you have to do is to take the distance between the camera and the layer and divide that by the zoom value, then multiply that by 100 to keep the layer at an effective 100% scale. I've split up this expression into more parts than are necessary just so that you can see what's going on.
c = thisComp.layer("Camera 1"); point1 = position; point2 = c.position; d = length(point1, point2); s = (d/c.zoom) * 100; [s, s, 100]
The first line just seta a variable for the camera so you don't have to type it out
The second line defines point1 as the layer's position
The second line defines point2 as the camera (c) position
The third defines d as the distance between the camera and the layer using vector math straight from the Expression Language Menu
The fourth line defines a value for scale by dividing the distance between the layer and the camera by the camera's zoom value then multiplying that by 100
The last line sets up an array for the x y and z scale values. The reason that the z value in the array is set to 100 is to keep the layer from moving around in funny ways if you have moved the anchor point in Z space. If you don't move the anchor point in Z then you could write the array like this: [s, s, s]
I hope this makes sense, and I hope it gives you an idea of how expressions can be written. Once you understand the language they are a powerful tool that will make your life much easier.
This expression seems to not work if I have a layer with this expression parented to a 3D Null.
Sound I change point1 = thisComp.layer("Null").transform.position; ?
Or is there a way to incorporate the parent transforms within the expression?
2 people found this helpful
To account for any parenting, try changing the 2nd and 3rd lines to:
point1 = toWorld(anchorPoint);
point2 = c.toWorld([0,0,0]);
1 person found this helpful
I know this is a really old post, but I had been looking for the answer to this question as well. I don't remember where I finally found it, but it works for me so I though I would put it here for people who come across this question.
This script should be placed in the Scale field of the layer that will retain its size (make sure 3D is activated before using).
“Primary Camera” is the name you give to the camera layer you want the expression to respond to.
This worked perfectly, thank you!