Activity › Forums › Adobe After Effects Expressions › offset on local y-axis of auto positioned and rotated object between two points
-
offset on local y-axis of auto positioned and rotated object between two points
Griffin Englander replied 9 years, 2 months ago 4 Members · 18 Replies
-
Dan Ebberts
April 29, 2017 at 6:28 pmGetting back to your original question, you could try something like this for position:
p1 = thisComp.layer(“A”).transform.position;
p2 = thisComp.layer(“B”).transform.position;
vec = p2 – p1;
n = normalize(vec);
s = effect(“Slider Control”)(“Slider”);
(p1+p2)/2 + s*[n[1],-n[0]]Dan
-
Lars Jandel
April 29, 2017 at 6:42 pmDan – you did it again!
This is what I was aiming for. Just a few lines of code – fantastic.
Thanks to you, I am having now the intended result and
thanks to Steve an alternative for a dynamic option!Have a nice weekend Dan,
thanks again,
cheers,
Lars. ???? -
Dan Ebberts
April 29, 2017 at 10:22 pmJust for fun, here’s a version that works for both x and y offsets (separate sliders):
p1 = thisComp.layer(“A”).transform.position;
p2 = thisComp.layer(“B”).transform.position;
vec = p2 – p1;
n = normalize(vec);
sx = effect(“X Offset”)(“Slider”);
sy = effect(“Y Offset”)(“Slider”);
(p1+p2)/2 + sy*[n[1],-n[0]] + sx*nDan
-
Lars Jandel
April 30, 2017 at 6:51 amGood Morning Dan!
Thanks so much! Now, with even more control. ????
An x offset via percentage, 0 for A, 50 for center, 100 for B with override was easy and I already had that.
Now with a pixel based offset on the x axis, another optional control – great!To make this series “complete”:
Would it be possible to have a third slider, which could be set to e.g. -1, 0, 1 and this would define the start for the offset in pixels on the x axis?
0 : as right now, from the center
-1 : starting from A
1 : starting from BThanks so much for you time – as long you are having fun! ????
Lars
-
Lars Jandel
May 1, 2017 at 6:29 amHi Dan,
I managed to add the last idea myself and the code looks still okay. ????
Nice thing about this 3rd slider, you can use it for a proportional offset of C itself – based on the distance of A and B. First I was only thinking about the space between A and B, but with this multiplier, you have the additional option to place it outside but still on the same vector calculated from A and B. Just like the x offset slider was already doing it, but now from a defined position on the scale running trough A and B.Thanks, Lars.
p1 = thisComp.layer("A").transform.position;
p2 = thisComp.layer("B").transform.position;
vec = p2 - p1;
n = normalize(vec);
sx = effect("X Offset")("Slider");
sy = effect("Y Offset")("Slider");
so = effect("X Offset Origin")("Slider");
(p1+p2)/2 + sy*[n[1],-n[0]] + sx*n + so*vec/2 -
Griffin Englander
May 8, 2017 at 6:39 amAmazing, Dan!
If I wanted A and B parented to another Null in the center, how do I reference their new position accordingly?
-
Dan Ebberts
May 8, 2017 at 7:01 amI haven’t tested it, butit would probably be like this:
L1 = thisComp.layer(“A”);
L2 = thisComp.layer(“B”);
p1 = L1.toComp(L1.anchorPoint);
p2 = L2.toComp(L2.anchorPoint);
vec = p2 – p1;
n = normalize(vec);
s = effect(“Slider Control”)(“Slider”);
(p1+p2)/2 + s*[n[1],-n[0]]Dan
Reply to this Discussion! Login or Sign Up
