Skip to main content
Community Expert
July 25, 2023
Answered

Using Scale of a 2D layer to control Camera Position.

  • July 25, 2023
  • 1 reply
  • 610 views

I have a layer that needs to be 2D in a 3D comp. The 2D layer needs to stay the same size relative to the 3D layers in the scene as the camera moves. I have been fiddling with an expression that calculates the distance from the camera to the comp center and uses that distance to change the scale of the 3D layer so as the layer camera gets closer to the comp center, the scale of the 2D layer decreases. I need the 2D layer to look like it is a 3D layer by adjusting the scale as the camera moves. The comp would also work if the camera position changes as I animate the scale of the 2D layer. So far, I'm getting pretty close by setting keyframes and adjusting the speed graph, but I'd like to simplify the process.

 

I have tried various combinations of multipliers, but I can't get it right. I thought it would be a simple exponential expression, but that's not even close. Does anyone have any ideas?

This topic has been closed for replies.
Correct answer Dan Ebberts

I think the simplest would be if the expression can assume the camera's z axis passes through the center point of the comp, in which case the camera's position expression might be as simple as this:

target = thisComp.layer("2D Layer");
m = target.scale[0]/100;
[value[0],value[1],value[2]/m]

Otherwise, I think it might get really complicated in a hurry.

 

1 reply

Dan Ebberts
Community Expert
Community Expert
July 25, 2023

I think for it to work, you need a reference value, where if the camera is that far away, the scale is 100%. Depending on how you have things set up, you might be able to use the camera's zoom value for that, in which case I think the 2D layer's scale expression would look something like this:

c = thisComp.layer("Camera 1");
v1 = toWorld(anchorPoint) - c.toWorld([0,0,0]);
v2 = c.toWorldVec([0,0,1]);
m = c.cameraOption.zoom/dot(v1,v2);
value*m
Community Expert
July 25, 2023

Thank you, Dan. That works great for Scale on the 2D layer.

 

Do you have any ideas on moving the camera based on the scale of the 2D layer?

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
July 25, 2023

I think the simplest would be if the expression can assume the camera's z axis passes through the center point of the comp, in which case the camera's position expression might be as simple as this:

target = thisComp.layer("2D Layer");
m = target.scale[0]/100;
[value[0],value[1],value[2]/m]

Otherwise, I think it might get really complicated in a hurry.