Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Conditionally offsetting a value

  • Conditionally offsetting a value

    Posted by Jovan Mikonjic on December 22, 2014 at 12:55 am

    Hello everyone,

    I am a beginner with expressions and i’m having some trouble conceptualizing this:
    I have a layer moving on x axis,
    and would like to set it up that when it goes out of the left end of the composition
    it comes in from the right end, and vice versa.

    I am using the expression below, but the layer can jump across the comp only once.

    *The x position of the layer is parented to a rotation value of a layer that I am using as a controller.

    I would really appreciate some help.

    X = position[0];
    Y = position[1];
    if (X > -300)
    {
    [X,Y]
    }else{
    [X+thisComp.width+600,Y];}

    Kevin Camp replied 11 years, 4 months ago 3 Members · 6 Replies
  • 6 Replies
  • Kevin Camp

    December 22, 2014 at 6:44 pm

    i’m not sure if this will work for your set up, but in a simple situation with a layer moving from offscreen-right to offscreen-left this would make it repeat:
    loopOut()

    Kevin Camp
    Art Director
    KCPQ, KZJO & KRCW

  • Jovan Mikonjic

    December 22, 2014 at 8:48 pm

    Thanks Kevin,

    But this situation is more complex because value will vary depending on an external controller.

  • Jovan Mikonjic

    December 22, 2014 at 9:56 pm

    I got this working, but it will only move the layer to the opposite side once,
    while input for the movement comes from a rotation value of another layer that will turn multiple circles… maybe theres a solution here..

    I am actually animating an panoramic projection, this is why I am trying to have left and right sides of the comp ‘meet’.

    X=position[0];
    Y=position[1];
    if (X < thisComp.width-thisComp.width)
    {
    [X+thisComp.width,Y];
    }
    else if (X >thisComp.width)
    {
    [X-thisComp.width,Y];}
    else
    [X,Y]

  • Dan Ebberts

    December 23, 2014 at 4:26 am

    It’s hard to picture how you have things set up exactly, but if there’s a relationship between the layer’s position and the other layer’s rotation, you can reduce the rotation to a value between 0 and 360 by doing something like this:

    r = thisComp.layer(“other layer”).rotation%360;

    Dan

  • Jovan Mikonjic

    December 23, 2014 at 5:09 pm

    Dear Dan,

    thanks for the tip,
    I will report if it does the trick.

    Maybe you can also help me with understanding how to approach this problem:

    I have set up an expression that will forward the position of a layer
    from one side of the comp to the other, if the layer position value is smaller or greater than the comp width.

    But the problem comes when it travels like this multiple times
    The expression is not self aware,
    it is returning a new value to the layer position.
    And this new value is not affected by the expression again and again.

    In this case:

    when the expression does its thing – the layer position goes from 0 to 3072, that is the right end of the comp

    If the layer would then go again to the left end of the comp, so the new value is -3072 (value in yellow)
    and the value affected by the expression is 0 (value in red)

    The expression will not work on the red value.

    How could I overcome this limit of the expression?

    My best idea is to have the if clause for every instance
    0, -3072, -6144.. and so on?

    Is it possible to have it address the ‘red value’ in some way?

    Thank you!!

    X=position[0];
    Y=position[1];
    if (X <= 0)
    {
    [X+thisComp.width,Y];
    }
    else if (X >= 3072)
    {
    [X-thisComp.width,Y];}
    else
    [X,Y]

  • Kevin Camp

    December 23, 2014 at 10:13 pm

    I don’t see how rotation of another layer is being used in your expression (it looks like it is evaluating keyframed values), but you may be able to loop the position output in a similar way to how Dan proposed looping a rotation input.

    try something like this for the position:

    x = value[0]%thisComp.width;
    [x,value[1]]

    it’s impossible to test it out on my end since i don’t have the whole picture of how you have things set up.

    Kevin Camp
    Art Director
    KCPQ, KZJO & KRCW

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