Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects expressions / camera distance

  • expressions / camera distance

    Posted by Alex Harding on November 3, 2006 at 5:23 pm

    i wonder could anyone please help me
    i want to make a text number that descreases in value as the camera approaches in 3d space. I have found the “number” effect which displays digits in the comp, the value of which can be defined by expressions.

    i need to know how to calculate the distance from the camera to the layer on which the effect resides with an expression.

    can anyone help?
    thanks in advance
    alex

    Alex Harding replied 19 years, 6 months ago 5 Members · 6 Replies
  • 6 Replies
  • Julian Sixx

    November 3, 2006 at 5:52 pm

    Hi
    i’m not sure if that is what you’re looking for.

    Let’s assume when the camera moves from -600 to -400 in z-space the Number effects counts from 40 to 20

    driver=thisComp.layer(“Kamera 1”).transform.position[2];
    minCam=-400
    maxCam=-600
    minNr=20
    maxNr=40
    linear(driver, minCam, maxCam, maxNr,minNr)

  • Alex Harding

    November 3, 2006 at 6:27 pm

    thanks for your help,
    that helped, but it isn’t quite what im after

    perhaps if i explain what i’m doing..

    i want to have a series of graphical “reticals” in the HUD of a spaceship that act as guides as it lands; the camera passes through them one after the other in 3d space. i want each one to display a number that represents the distance from the space ship (the camera) to that point in space, hitting 0 at the moment that the camera ocupies the same coordinates. (nerdy i know)

    so ideally i need to calculate a value representing the distance between the points irrespective of what axes that distance lies in.

    is this rediculously complicated?

    any help will be appreciated, thanks
    alex

  • Mike Clasby

    November 3, 2006 at 7:49 pm

    This should do what you want, you need a little vector math to calculate the distance from the rocket (camera) to your HUD. For any HUD layer add this expression to the Value/Offset (alt click the Stopwatch) of the Numbers Effect:

    point1=this_layer.position;
    point2=thisComp.layer(“Camera 1”).position;
    delta=sub(point1, point2);// Find the vector between them
    distance=length(delta);// Now find the length
    linear(distance, 0,10000, 0, 10000);

    This limits out at 10,000 pixels so if you want you camera father away, change the 10,000’s to whatever figure you want. If you want the numbers to change slower you could skew the linear interpolation to something like this:

    linear(distance, 0,10000, 0, 1000);

    Now the 10 pixels equals 1 until of camera travel (meters in Outer Space Distance?)

    This is a modification from here:
    https://jjgifford.com/expressions/geometry/length.html
    Example: Interactive Blur

  • Dan Ebberts

    November 3, 2006 at 7:49 pm

    I’d use a text layer with an expression like this for Source Text:

    length(thisComp.layer(“Camera 1”).position,position)

    Dan

  • Colin Braley

    November 3, 2006 at 8:01 pm

    Does this one do the trick?

    //begin
    p1 = thisComp.layer(“Camera”).position;
    p2 = thisComp.layer(“HUD”).position;
    distance = Math.round( length( p1 , p2 ) ) ;
    distance
    //end

    ~Colin

  • Alex Harding

    November 6, 2006 at 2:02 pm

    perfect.
    thanks!

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy