FORUMS: list search recent posts

# Reposition a layer along a 3D vector

FAQ   •   VIEW ALL
 Reposition a layer along a 3D vector on Nov 19, 2015 at 10:08:58 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

 Re: Reposition a layer along a 3D vectoron Nov 19, 2015 at 11:32:41 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

 Re: Reposition a layer along a 3D vectoron Nov 20, 2015 at 8:37:03 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

 Re: Reposition a layer along a 3D vectoron Nov 20, 2015 at 8:43:05 pm

Normalizing gives the vector a length of 1.

Dan