Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions offset on local y-axis of auto positioned and rotated object between two points

  • Dan Ebberts

    April 29, 2017 at 6:28 pm

    Getting back to your original question, you could try something like this for position:

    p1 = thisComp.layer(“A”).transform.position;
    p2 = thisComp.layer(“B”).transform.position;
    vec = p2 – p1;
    n = normalize(vec);
    s = effect(“Slider Control”)(“Slider”);
    (p1+p2)/2 + s*[n[1],-n[0]]

    Dan

  • Lars Jandel

    April 29, 2017 at 6:42 pm

    Dan – you did it again!
    This is what I was aiming for. Just a few lines of code – fantastic.
    Thanks to you, I am having now the intended result and
    thanks to Steve an alternative for a dynamic option!

    Have a nice weekend Dan,
    thanks again,
    cheers,
    Lars. ????

  • Dan Ebberts

    April 29, 2017 at 10:22 pm

    Just for fun, here’s a version that works for both x and y offsets (separate sliders):

    p1 = thisComp.layer(“A”).transform.position;
    p2 = thisComp.layer(“B”).transform.position;
    vec = p2 – p1;
    n = normalize(vec);
    sx = effect(“X Offset”)(“Slider”);
    sy = effect(“Y Offset”)(“Slider”);
    (p1+p2)/2 + sy*[n[1],-n[0]] + sx*n

    Dan

  • Lars Jandel

    April 30, 2017 at 6:51 am

    Good Morning Dan!

    Thanks so much! Now, with even more control. ????
    An x offset via percentage, 0 for A, 50 for center, 100 for B with override was easy and I already had that.
    Now with a pixel based offset on the x axis, another optional control – great!

    To make this series “complete”:
    Would it be possible to have a third slider, which could be set to e.g. -1, 0, 1 and this would define the start for the offset in pixels on the x axis?
    0 : as right now, from the center
    -1 : starting from A
    1 : starting from B

    Thanks so much for you time – as long you are having fun! ????

    Lars

  • Lars Jandel

    May 1, 2017 at 6:29 am

    Hi Dan,

    I managed to add the last idea myself and the code looks still okay. ????
    Nice thing about this 3rd slider, you can use it for a proportional offset of C itself – based on the distance of A and B. First I was only thinking about the space between A and B, but with this multiplier, you have the additional option to place it outside but still on the same vector calculated from A and B. Just like the x offset slider was already doing it, but now from a defined position on the scale running trough A and B.

    Thanks, Lars.

    p1 = thisComp.layer("A").transform.position;
    p2 = thisComp.layer("B").transform.position;
    vec = p2 - p1;
    n = normalize(vec);
    sx = effect("X Offset")("Slider");
    sy = effect("Y Offset")("Slider");
    so = effect("X Offset Origin")("Slider");
    (p1+p2)/2 + sy*[n[1],-n[0]] + sx*n + so*vec/2

  • Griffin Englander

    May 8, 2017 at 6:39 am

    Amazing, Dan!

    If I wanted A and B parented to another Null in the center, how do I reference their new position accordingly?

  • Dan Ebberts

    May 8, 2017 at 7:01 am

    I haven’t tested it, butit would probably be like this:

    L1 = thisComp.layer(“A”);
    L2 = thisComp.layer(“B”);
    p1 = L1.toComp(L1.anchorPoint);
    p2 = L2.toComp(L2.anchorPoint);
    vec = p2 – p1;
    n = normalize(vec);
    s = effect(“Slider Control”)(“Slider”);
    (p1+p2)/2 + s*[n[1],-n[0]]

    Dan

  • Griffin Englander

    May 8, 2017 at 7:25 am

    That does it! Thanks!

Page 2 of 2

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