Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Spreading layers out in 3D space by slider control?

  • Spreading layers out in 3D space by slider control?

    Posted by Thai Tran on August 30, 2007 at 2:23 am

    I’m in need of some expression help. I have a certain number of layers in 3D space. I want to be able to evenly space them from each other based on a slider control. Bigger value of the slider, the farther apart they are spaced. I know this is probably a rather simple expression, but I’m not mathematically inclined … at all. A little help would be great!

    “If at first you don’t succeed, destroy all evidence that you tried in the first place.”

    Mike Clasby replied 18 years, 8 months ago 3 Members · 3 Replies
  • 3 Replies
  • Colin Braley

    August 30, 2007 at 2:58 am

    Were going to need some more information…how exactly do you want them spread out? Along the x axis, y axis, or z axis?

    Well try this code out, it distributes them along the z axis:


    gap = 100;
    startingPos = [ 360 , 240, 0 ];
    //--
    dispVec = [0, 0, 1];
    i = index - 1;
    startingPos + (i * gap * dispVec)

    Change the gap variable to adjust the gap between each layer, and change startingPos to adjust the position of the first layer. Also note that I can’t test this right now, no AE on my laptop, but I’m pretty sure it should work out alright. If you want to displace along the x axis, change the line beginning with dispVec to dispVec = [1, 0, 0]

    ~Colin

    http://www.colinbraley.com

  • Mike Clasby

    August 30, 2007 at 3:08 am

    Name your first layer “Leader” (Select layer, “Enter”, name it).

    Add a slider control (Effect>Expression Controls>Slider Control. Name the slider “zSpread” (select the slider in the Effect Panel, Enter, name it).

    Add your next layer.

    Put this expression on Position (Copy the expression, double click the Position Stopwatch, Paste, click outside the expression box):

    offset = thisComp.layer(“Leader”).effect(“zSpread”)(“Slider”);
    x = thisComp.layer(“Leader”).position[0];
    y = thisComp.layer(“Leader”).position[1];
    z = thisComp.layer(“Leader”).position[2] + (index-1)*offset;
    [x, y, z]

    Now if you duplicate that layer they will have the same position as Leader, until you put a number on the slider, then they’ll spread out evenly that much.

    Note: They need to be at the top of the layer stack, with leader at the very top.

    If you’re not duplicating layers to make you train, select the position for that layer with the expression, then Edit>Copy Expression Only, and Paste onto as many selected layers as you want to have the expression.

  • Mike Clasby

    August 30, 2007 at 3:09 am

    Did see you Colin, I’m slow writing them.

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