Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Limit movement to Comp dimensions

  • Limit movement to Comp dimensions

    Posted by Andreas Woelfl on September 22, 2016 at 10:25 am

    Hello everybody,

    I am trying to write a script that allows me to grab and move an element inside the comps borders, but only within the comp’s width and height. So even if I would drag the element outside the comp it would stay at the border of the comp.

    Please find the script that I added to the object in my comp below.

    With the script that I have so far it works visual wise. So the square gets stuck on the comp border when ever I try to drag it outside the comp. The only problem I have is that it seems that if I drag the square for example 5000px to the right outside the comp it stucks directly at the border. But when I want to drag it back in the middle I have to drag it at first 5000px back to the left until I can see the square moving inside the comp.

    Can anybody tell me if I need an adjustment to my code or maybe a complete other aproach?

    Thanks for the help!

    xPos = transform.position[0];

    if (transform.position[0]>1920) {
    xPos = 1920
    }
    if (transform.position[0]<0) {
    xPos = 0
    };

    yPos = transform.position[1];

    [xPos, yPos]

    Xavier Gomez replied 9 years, 10 months ago 2 Members · 2 Replies
  • 2 Replies
  • Xavier Gomez

    September 22, 2016 at 12:40 pm

    An expression can bypass the value as you did, but cannot prevent you to set a given value.
    I dont think there is a way to do what you want.

    Note: you could shorten the expression, and make it valid for any comp size, as follows:

    pos = value;
    pos[0] = clamp(pos[0], 0, thisComp.width);
    pos;

    Xavier

  • Xavier Gomez

    September 22, 2016 at 12:47 pm

    You could also hit P to reveal the position property of the layer, then either :
    right click the position property, > reset to recenter,
    or shift+scroll the x value to scroll faster.

    Xavier

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