FORUMS: list search recent posts

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

FAQ   •   VIEW ALL
 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.

 Re: offset on local y-axis of auto positioned and rotated object between two pointson 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 !

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

Hi Steve,

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;

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.

 Re: offset on local y-axis of auto positioned and rotated object between two pointson 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 ?
;)

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

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

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

๐

 Re: offset on local y-axis of auto positioned and rotated object between two pointson 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 ?

 Re: offset on local y-axis of auto positioned and rotated object between two pointson 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. :)

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

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..?

 Re: offset on local y-axis of auto positioned and rotated object between two pointson 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 !

 Re: offset on local y-axis of auto positioned and rotated object between two pointson 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!

 Re: offset on local y-axis of auto positioned and rotated object between two pointson 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

 Re: offset on local y-axis of auto positioned and rotated object between two pointson 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. ๐

 Re: offset on local y-axis of auto positioned and rotated object between two pointson 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

 Re: offset on local y-axis of auto positioned and rotated object between two pointson 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

 Re: offset on local y-axis of auto positioned and rotated object between two pointson 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```

 Re: offset on local y-axis of auto positioned and rotated object between two pointson 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?

 Re: offset on local y-axis of auto positioned and rotated object between two pointson 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