FORUMS: list search recent posts

offset on local y-axis of auto positioned and rotated object between two points

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Lars Jandel
offset on local y-axis of auto positioned and rotated object between two points
on Apr 28, 2017 at 2:14:20 pm

I am struggling with the following set up:

I have the usual set up, having one object (C) centered between two others (A+B), including being auto oriented. Now, I like to use a slider on C to control a y-offset on the virtual line between A and B. This would be easy, if A+B would stay on the same y value, because then the world axis would work fine. Now, when one object has a different y value, the virtual line gets tilted and the orthogonal line for the offset doesn't match the world axis anymore... Changing the anchor on y does the job, respecting the local axis, but would not work with the next wish, to shift+connect a child to it.

My goal is to parent another object to C, after the y-offset is done. If you parent it first, it would be easy to use the anchor point afterwards. But when doing the offset first, the child gets positioned at the original position. Zeroing out the y-position of the child would achieve the desired result, but I would prefer, not to do these additional steps. ๐Ÿ˜‰

So my question is, is there an expression to add a y-offset to the position of the centered and rotated object via a slider, respecting it's current local y-axis? So a child could always be shift-parented afterwards without any additional steps?

Thanks, Lars.


Return to posts index

Steve Sierra
Re: offset on local y-axis of auto positioned and rotated object between two points
on Apr 28, 2017 at 3:18:31 pm

Hi,

Here's a way to do it :

- parent C to A.
- seperate position dimensions for all three objects.
- add a slider control to C.
- in C's X Position, put this expression :

var a = (thisComp.layer("B").transform.xPosition-thisComp.layer("A").transform.xPosition);
var s = effect("Slider Control")("Slider");
a*s/100;

-in C's Y Position, put this one :

var a = (thisComp.layer("B").transform.yPosition-thisComp.layer("A").transform.yPosition);
var s = effect("Slider Control")("Slider");
a*s/100

Does that help ?
Cheers !


Return to posts index

Lars Jandel
Re: offset on local y-axis of auto positioned and rotated object between two points
on Apr 28, 2017 at 3:59:13 pm

Hi Steve,

thanks for your reply!
Your set up works great for the "x"-position between A and B. But I was aiming for the "y"-offset. ๐Ÿ˜‰
Maybe you have an idea for that as well. Plus I would prefer to have C not parented, but everything set via expressions. ATM for centering, I use in the position of C:

p1 = thisComp.layer("A").transform.position;
p2 = thisComp.layer("B").transform.position;
(p1+p2)/2

โ€ฆyes, I will add a slider to that later on as well. ๐Ÿ˜‰
In the rotation of C, I use:

p1 = thisComp.layer("A").transform.position;
p2 = thisComp.layer("B").transform.position;
vec = p2 - p1;
radiansToDegrees(Math.atan2(vec[1], vec[0]))

Now, it would be fantastic to add a "y"-offset to the position via a slider, which works in a rotated mode as well.

Thanks, Lars.



Return to posts index


Steve Sierra
Re: offset on local y-axis of auto positioned and rotated object between two points
on Apr 28, 2017 at 4:31:50 pm

Hi again,

With the same setup as my first post, you can do this :

-add a second slider to C.
- replace X expression :

var a = (thisComp.layer("B").transform.xPosition-thisComp.layer("A").transform.xPosition);
var s = effect("Slider Control")("Slider");
var s2 = effect("Slider Control 2")("Slider");
(a*s/100) + s2;

- replace Y expression :

var a = (thisComp.layer("Null 2").transform.yPosition-thisComp.layer("Null 1").transform.yPosition);
var s = effect("Slider Control")("Slider");
var s2 = effect("Slider Control 2")("Slider");
(a*s/100) + s2;

Does that help ?
;)


Return to posts index

Steve Sierra
Re: offset on local y-axis of auto positioned and rotated object between two points
on Apr 28, 2017 at 4:36:17 pm

I just saw my last post doesn't work... The offset needs to be rotated....


Return to posts index

Lars Jandel
Re: offset on local y-axis of auto positioned and rotated object between two points
on Apr 28, 2017 at 4:38:54 pm

๐Ÿ˜ƒ
Was just about to answerโ€ฆSliding funny ;)


Return to posts index


Steve Sierra
Re: offset on local y-axis of auto positioned and rotated object between two points
on Apr 28, 2017 at 5:02:53 pm

I get very funny slides mixing x and y....

here's one I think works :

Same setup, but unliked C from A and added A pos to my expressions.

in X:
var a = (thisComp.layer("B").transform.xPosition-thisComp.layer("A").transform.xPosition);
var aY = (thisComp.layer("B").transform.yPosition-thisComp.layer("A").transform.yPosition);
var s = effect("Slider Control")("Slider");
var s2 = effect("Slider Control 2")("Slider");
(a*s/100) + thisComp.layer("A").transform.xPosition - aY*s2/100

in Y:
var a = (thisComp.layer("B").transform.yPosition-thisComp.layer("A").transform.yPosition);
var aX = (thisComp.layer("B").transform.xPosition-thisComp.layer("A").transform.xPosition);
var s = effect("Slider Control")("Slider");
var s2 = effect("Slider Control 2")("Slider");

a*s/100 + thisComp.layer("A").transform.yPosition + aX*s2/100

Any better ?


Return to posts index

Lars Jandel
Re: offset on local y-axis of auto positioned and rotated object between two points
on Apr 28, 2017 at 5:10:28 pm

YES - it works!!!
Thanks so much Steve โ˜บ
I was looking through the forums and trying stuff myself, but couldn't figure it outโ€ฆ
And your solution is just as I like it, without limitations (using a linear expression) - perfect!

Thanks again, Lars. :)


Return to posts index

Lars Jandel
Re: offset on local y-axis of auto positioned and rotated object between two points
on Apr 28, 2017 at 6:34:16 pm

As a follow up:
I will definitely use the solution - it does, what I was aiming for and is very dynamic.
Now I was just wondering, if it would be possible to achieve a fixed offset on the y-axis. Right now, the offset works in proportion to the distance between A and B: As they get closer the offset shrinks and vice versa. As said, it is nice and cool to bring all objects to the same point when compressing the distance.
As an alternative, it would be great to set a fixed offset in pixels via the slider. I played a bit with the expression, but as it is quite hard for me to bend my head around these vector(?) calculations, I did not succeed... ๐Ÿ˜ƒ
Don't know, if this is possible..?


Return to posts index


Steve Sierra
Re: offset on local y-axis of auto positioned and rotated object between two points
on Apr 29, 2017 at 5:38:23 am

Hi Lars,

I can't seem to get what you need.... not a vector pro either ๐Ÿ˜‰
I'll continue playing with the expression when I have a bit of time.

Meanwhile, maybe one of the real expressioneers can help you out !

Good luck !


Return to posts index

Lars Jandel
Re: offset on local y-axis of auto positioned and rotated object between two points
on Apr 29, 2017 at 5:46:41 am

Thanks Steve!
The first solution is already great.
Yeah, maybe there is a completely different approach - let's see, if so speaks up. ;)
Thanks again for your time and one working set up - will be used for sure!


Return to posts index

Dan Ebberts
Re: offset on local y-axis of auto positioned and rotated object between two points
on Apr 29, 2017 at 6:28:47 pm

Getting 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



Return to posts index


Lars Jandel
Re: offset on local y-axis of auto positioned and rotated object between two points
on Apr 29, 2017 at 6:42:39 pm

Dan - 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. ๐Ÿ˜Š


Return to posts index

Dan Ebberts
Re: offset on local y-axis of auto positioned and rotated object between two points
on Apr 29, 2017 at 10:22:37 pm

Just 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*n


Dan



Return to posts index

Lars Jandel
Re: offset on local y-axis of auto positioned and rotated object between two points
on Apr 30, 2017 at 6:51:24 am

Good 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 B

Thanks so much for you time - as long you are having fun! ๐Ÿ˜‰

Lars


Return to posts index


Lars Jandel
Re: offset on local y-axis of auto positioned and rotated object between two points
on May 1, 2017 at 6:29:16 am

Hi 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


Return to posts index

Griffin Englander
Re: offset on local y-axis of auto positioned and rotated object between two points
on May 8, 2017 at 6:39:50 am

Amazing, Dan!

If I wanted A and B parented to another Null in the center, how do I reference their new position accordingly?


Return to posts index

Dan Ebberts
Re: offset on local y-axis of auto positioned and rotated object between two points
on May 8, 2017 at 7:01:49 am

I 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



Return to posts index

Griffin Englander
Re: offset on local y-axis of auto positioned and rotated object between two points
on May 8, 2017 at 7:25:03 am

That does it! Thanks!


Return to posts index

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