FORUMS: list search recent posts

Limit movement to Comp dimensions

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Andreas Woelfl
Limit movement to Comp dimensions
on Sep 22, 2016 at 10:25:31 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]&lt;0) {
xPos = 0
};

yPos = transform.position[1];

[xPos, yPos]


Return to posts index

Xavier Gomez
Re: Limit movement to Comp dimensions
on Sep 22, 2016 at 12:40:56 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


Return to posts index

Xavier Gomez
Re: Limit movement to Comp dimensions
on Sep 22, 2016 at 12:47:48 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


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]