Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Reposition a layer along a 3D vector

  • Reposition a layer along a 3D vector

    Posted by Rob Womack on November 19, 2015 at 10:08 pm

    I have a layer whose distance I want to change, moving along along its current vector.


    var cam = thisComp.activeCamera;
    delta=sub( cam.toWorld([0,0,0]), this.toWorld(this.anchorPoint) );
    var dist = length(delta);

    delta represents the vector between the layer and the camera, and dist represents the distance. What I’d like to do is to be able to change the distance to a specific value, but reposition the layer along the delta vector, so it would essentially be moving directly toward or away from the camera.

    This is a big gap in my understanding of vectors and such. Would I need to use trig functions, or cam.toWorld? My gut tells me it might require matrix math, which I don’t get in EMCA script at all.

    Any help is greatly appreciated.

    Robert Womack
    Creative Bridgekeep
    http://www.CurrentMarketing.com
    “Louisville’s Leading Interactive Marketing Agency”

    Dan Ebberts replied 10 years, 5 months ago 2 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    November 19, 2015 at 11:32 pm

    I think something like this should work:

    offset = effect(“Slider Control”)(“Slider”);
    cam = thisComp.activeCamera;
    p = toWorld(anchorPoint);
    v = normalize(cam.toWorld([0,0,0]) – p); // unit vector from layer to cam
    value + fromWorldVec(offset*v);

    Dan

  • Rob Womack

    November 20, 2015 at 8:37 pm

    That’s it! I’m going to remember you in my memoirs, Dan.

    So, normalizing the vector is what I currently don’t get. You normalize it to make it a unit vector of length 1. So, if my distance is 3.45678 pixels, normalizing represents 3.45678 as 1 unit, right? But each integer difference in the slider value moves the object by 1 pixel, even though we’re multiplying. In my mind, the slider value of 1 would mean 1 * 3.45678, which would leave it where it is. A value of 2 would mean it moves away from the camera 6.91356 pixels. Clearly, this is not the case. What am I misunderstanding here?

    And thanks again.

    Robert Womack
    Creative Bridgekeep
    http://www.CurrentMarketing.com
    “Louisville’s Leading Interactive Marketing Agency”

  • Dan Ebberts

    November 20, 2015 at 8:43 pm

    Normalizing gives the vector a length of 1.

    Dan

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