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

  • offset on local y-axis of auto positioned and rotated object between two points

    Posted by Lars Jandel on April 28, 2017 at 2:14 pm

    I am struggling with the following set up:

    I have the usual set up, having one object (C) centered between two others (A+B), including being auto oriented. Now, I like to use a slider on C to control a y-offset on the virtual line between A and B. This would be easy, if A+B would stay on the same y value, because then the world axis would work fine. Now, when one object has a different y value, the virtual line gets tilted and the orthogonal line for the offset doesn’t match the world axis anymore… Changing the anchor on y does the job, respecting the local axis, but would not work with the next wish, to shift+connect a child to it.

    My goal is to parent another object to C, after the y-offset is done. If you parent it first, it would be easy to use the anchor point afterwards. But when doing the offset first, the child gets positioned at the original position. Zeroing out the y-position of the child would achieve the desired result, but I would prefer, not to do these additional steps. ????

    So my question is, is there an expression to add a y-offset to the position of the centered and rotated object via a slider, respecting it’s current local y-axis? So a child could always be shift-parented afterwards without any additional steps?

    Thanks, Lars.

    Griffin Englander replied 9 years ago 4 Members · 18 Replies
  • 18 Replies
  • Steve Sierra

    April 28, 2017 at 3:18 pm

    Hi,

    Here’s a way to do it :

    – parent C to A.
    – seperate position dimensions for all three objects.
    – add a slider control to C.
    – in C’s X Position, put this expression :

    var a = (thisComp.layer(“B”).transform.xPosition-thisComp.layer(“A”).transform.xPosition);
    var s = effect(“Slider Control”)(“Slider”);
    a*s/100;

    -in C’s Y Position, put this one :

    var a = (thisComp.layer(“B”).transform.yPosition-thisComp.layer(“A”).transform.yPosition);
    var s = effect(“Slider Control”)(“Slider”);
    a*s/100

    Does that help ?
    Cheers !

  • Lars Jandel

    April 28, 2017 at 3:59 pm

    Hi Steve,

    thanks for your reply!
    Your set up works great for the “x”-position between A and B. But I was aiming for the “y”-offset. ????
    Maybe you have an idea for that as well. Plus I would prefer to have C not parented, but everything set via expressions. ATM for centering, I use in the position of C:

    p1 = thisComp.layer(“A”).transform.position;
    p2 = thisComp.layer(“B”).transform.position;
    (p1+p2)/2

    …yes, I will add a slider to that later on as well. ????
    In the rotation of C, I use:

    p1 = thisComp.layer(“A”).transform.position;
    p2 = thisComp.layer(“B”).transform.position;
    vec = p2 – p1;
    radiansToDegrees(Math.atan2(vec[1], vec[0]))

    Now, it would be fantastic to add a “y”-offset to the position via a slider, which works in a rotated mode as well.

    Thanks, Lars.

  • Steve Sierra

    April 28, 2017 at 4:31 pm

    Hi again,

    With the same setup as my first post, you can do this :

    -add a second slider to C.
    – replace X expression :

    var a = (thisComp.layer(“B”).transform.xPosition-thisComp.layer(“A”).transform.xPosition);
    var s = effect(“Slider Control”)(“Slider”);
    var s2 = effect(“Slider Control 2”)(“Slider”);
    (a*s/100) + s2;

    – replace Y expression :

    var a = (thisComp.layer(“Null 2”).transform.yPosition-thisComp.layer(“Null 1”).transform.yPosition);
    var s = effect(“Slider Control”)(“Slider”);
    var s2 = effect(“Slider Control 2”)(“Slider”);
    (a*s/100) + s2;

    Does that help ?
    😉

  • Steve Sierra

    April 28, 2017 at 4:36 pm

    I just saw my last post doesn’t work… The offset needs to be rotated….

  • Lars Jandel

    April 28, 2017 at 4:38 pm

    ????
    Was just about to answer…Sliding funny 😉

  • Steve Sierra

    April 28, 2017 at 5:02 pm

    I get very funny slides mixing x and y….

    here’s one I think works :

    Same setup, but unliked C from A and added A pos to my expressions.

    in X:
    var a = (thisComp.layer(“B”).transform.xPosition-thisComp.layer(“A”).transform.xPosition);
    var aY = (thisComp.layer(“B”).transform.yPosition-thisComp.layer(“A”).transform.yPosition);
    var s = effect(“Slider Control”)(“Slider”);
    var s2 = effect(“Slider Control 2”)(“Slider”);
    (a*s/100) + thisComp.layer(“A”).transform.xPosition – aY*s2/100

    in Y:
    var a = (thisComp.layer(“B”).transform.yPosition-thisComp.layer(“A”).transform.yPosition);
    var aX = (thisComp.layer(“B”).transform.xPosition-thisComp.layer(“A”).transform.xPosition);
    var s = effect(“Slider Control”)(“Slider”);
    var s2 = effect(“Slider Control 2”)(“Slider”);

    a*s/100 + thisComp.layer(“A”).transform.yPosition + aX*s2/100

    Any better ?

  • Lars Jandel

    April 28, 2017 at 5:10 pm

    YES – it works!!!
    Thanks so much Steve ☺
    I was looking through the forums and trying stuff myself, but couldn’t figure it out…
    And your solution is just as I like it, without limitations (using a linear expression) – perfect!

    Thanks again, Lars. 🙂

  • Lars Jandel

    April 28, 2017 at 6:34 pm

    As a follow up:
    I will definitely use the solution – it does, what I was aiming for and is very dynamic.
    Now I was just wondering, if it would be possible to achieve a fixed offset on the y-axis. Right now, the offset works in proportion to the distance between A and B: As they get closer the offset shrinks and vice versa. As said, it is nice and cool to bring all objects to the same point when compressing the distance.
    As an alternative, it would be great to set a fixed offset in pixels via the slider. I played a bit with the expression, but as it is quite hard for me to bend my head around these vector(?) calculations, I did not succeed… ????
    Don’t know, if this is possible..?

  • Steve Sierra

    April 29, 2017 at 5:38 am

    Hi Lars,

    I can’t seem to get what you need…. not a vector pro either ????
    I’ll continue playing with the expression when I have a bit of time.

    Meanwhile, maybe one of the real expressioneers can help you out !

    Good luck !

  • Lars Jandel

    April 29, 2017 at 5:46 am

    Thanks Steve!
    The first solution is already great.
    Yeah, maybe there is a completely different approach – let’s see, if so speaks up. 😉
    Thanks again for your time and one working set up – will be used for sure!

Page 1 of 2

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