Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Change direction according to value

  • Change direction according to value

    Posted by Daniel Cantwell on August 15, 2016 at 10:17 am

    Hi

    Long time user and fan of this Forum but first time posting. I have a problem and I’m hoping someone here can help me. What I am trying to achieve is this. I have a Null in the centre of my screen that is clamped to go 400 pixels to the right and left. I need this null to move an object 200 pixels to the left as it goes 200 pixels to the right and as the null goes from 200 to 400 pixels I need the object to move 200 pixels back to its original position. I was also wondering would it be possible to have it work in reverse as the null moves back to the centre of the screen. I guess something along the lines of the way a lens flare moves only as you approach the edge of the screen with the controller the flare moves back to the centre. I hope this is clear enough. Any help would be greatly appreciated!

    All the best

    Dan

    Daniel Cantwell replied 9 years, 9 months ago 2 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    August 15, 2016 at 5:14 pm

    Something like this maybe:


    p = thisComp.layer("Null 1").position;
    d = p[0] - thisComp.width/2;
    if (d < 200)
    value - [d,0]
    else
    value + [d - 400,0]

    Dan

  • Daniel Cantwell

    August 16, 2016 at 10:13 am

    Hi Dan. First off thanks so much for replying, I’m a big fan. This expression works great! I was trying to push it a little further by having the same motion happen again when the Null goes to the left of the centre but I cant figure out how to structure the if else statements. I’ll keep looking but if you had the time I would be grateful if you could cast some light on it.

    All the best

    Daniel

  • Daniel Cantwell

    August 16, 2016 at 12:42 pm

    Hi Dan

    I figured out with the help of your expression how to get what I was looking for. The expression will probably make your eyes burn but here it is.

    Many thanks

    Daniel

    p = thisComp.layer("Null 1").position;
    d = p[0] - thisComp.width/2;
    if (d>0 && d&lt;200)
      value + [d,0]
    else if (d &lt; 0 && d > -200)
      value - [d,0]
    else if ( d &lt; -199 && d > -400)
     value + [d - 400,0]+800
    else if ( d > 199 && d &lt; 400)
      value - [d - 400,0]
    else
      value + [0,0]

  • Dan Ebberts

    August 16, 2016 at 1:22 pm

    This should work:


    p = thisComp.layer("Null 1").position;
    d = p[0] - thisComp.width/2;
    if (d < -200)
    value + [d + 400,0]
    else if (d < 200)
    value - [d,0]
    else
    value + [d - 400,0]

    Dan

  • Daniel Cantwell

    August 16, 2016 at 5:58 pm

    Hi Dan

    I understand it now. I’ve been working on a rig for days and for some reason I was thinking comp width was 1080 instead of 1920 like a dope so i couldn’t understand the expression. I’ve got it perfectly now thanks a lot for your help. I modified it for a 6000 comp connected to a null for a faux 3d Rig body rotation. It works great!

    All the best

    Daniel

    x = thisComp.layer("BODY_ROTATION").transform.position[0];
    if(x>1340 && x&lt;1400){
    }else if(x>-68 && x&lt;644){
    }else if(x>-1430 && x&lt;-768){
    [100];
    }else{ [0] ; }

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