-
Limit movement to Comp dimensions
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]