Skip to main content
Inspiring
October 18, 2022
Answered

Expressions. Finding an error

  • October 18, 2022
  • 1 reply
  • 346 views

Hi all.

Link to project file

https://drive.google.com/file/d/1FEXf970NN_MgKxgOmItByiXgOWM85kzk/view?usp=sharing  

 

Changing the Scale property, depending on the position of the camera.

 

When the camera approaches the composition being filmed,
the scale of the composition should change downwards.
And ultimately in the "Camera 1" window, the view should remain unchanged.

Property -- comp("Test").layer("CompA").transform.scale.expression =
--------------------------------------------------------------------
    CSP = [0,0,-2000]; //camera start position
    CP = thisComp.layer("CamControl").transform.position; //camera position
    Zero = [0,0,0];

    iniLenth = length(sub(CSP , Zero));

    carentLenth = length(sub(Zero, CP));

    carentScale = (carentLenth/iniLenth)*100;

    [carentScale, carentScale, carentScale];
---------------------------------------------------------------------

In my opinion, the expression is written correctly, but

When the camera approaches the composition being filmed,
its scale changes, and the initial value of the SCALE property is 104.1 ????

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

I think the problem is that you're calculating the distance from the camera to the target comp and the target comp is off the camera's z axis. Instead, you should calculate the distance to the camera's focal plane where it includes the target layer, kind of like explained here:

http://www.motionscript.com/design-guide/auto-focus.html

I'd do it like this:

c = thisComp.layer("Camera 1");
// get current distance
v1 = toWorld(anchorPoint) - c.toWorld([0,0,0]);
v2 = c.toWorldVec([0,0,1]);
d = dot(v1,v2);
// get initial distance
v1_0 = toWorld(anchorPoint,0) - c.toWorld([0,0,0],0);
v2_0 = c.toWorldVec([0,0,1],0);
d_0 = dot(v1_0,v2_0);

s = (d/d_0)*100;
[s,s,s]

 

1 reply

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
October 18, 2022

I think the problem is that you're calculating the distance from the camera to the target comp and the target comp is off the camera's z axis. Instead, you should calculate the distance to the camera's focal plane where it includes the target layer, kind of like explained here:

http://www.motionscript.com/design-guide/auto-focus.html

I'd do it like this:

c = thisComp.layer("Camera 1");
// get current distance
v1 = toWorld(anchorPoint) - c.toWorld([0,0,0]);
v2 = c.toWorldVec([0,0,1]);
d = dot(v1,v2);
// get initial distance
v1_0 = toWorld(anchorPoint,0) - c.toWorld([0,0,0],0);
v2_0 = c.toWorldVec([0,0,1],0);
d_0 = dot(v1_0,v2_0);

s = (d/d_0)*100;
[s,s,s]

 

AnyONAuthor
Inspiring
October 18, 2022

I have read the article. Yes, not everything is as simple as it seems. Thank you.