ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Move one layer in opposite direction (in Y axis) of another layer

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Kevin Dearing
Move one layer in opposite direction (in Y axis) of another layer
on Jan 6, 2020 at 5:40:32 pm

Hello all,
There very well may be a better way to do what I'm trying to use an expression for, but here's what I'm doing.. I have a sub comp that has the front, and the back of an image (a target) (3-d layers) The main comp, the camera will fly around to reveal the back of the image of the target. Additionally, I am using track mattes on them to put bullet holes in the front and the back based on another pre-comp - for the back, I just flip the subcomp so the wholes line up. The main comp will have a bullet fly through one of the holes.

All of this I have working beautifully right now.. I want the target to move a little when the bullet hits it, so I put individual wiggle expressions on the x y and z (linked to sliders for the values) on the layer of the precomp'd target. When viewed from the main comp the back of the target is moving up, when the front of the target it moving down, presumably because I had to flip the back so when the camera comes around it'll be aligned correctly. I.e. if the wiggle expression results in moving the Y postion + 20, the front image in the pre-comp does indeed move + 20, but the 'back' of the target, that layer moves in what appears to be -20. One goe up while the other moves down.

I'm trying to put an expression on the back of the target to detect the amount of the front's Y movement, then I can do something like value += -1 * movementDelta.

Oh, I almost forgot, I'm on an old version - CS4. I know that newer versions have upgraded effects like the shatter effect where you can specify the back image to be different than the front and etc, but I don't have that in CS4.


Return to posts index

Andrei Popa
Re: Move one layer in opposite direction (in Y axis) of another layer
on Jan 6, 2020 at 7:07:51 pm

I cant really re-create your situation to test this, but here is how i think you can solve it. Put this in the back layer's position

pos = thisComp.layer("Your fron layer").transform.position; //this is the front layer's position
startPos = pos.valueAtTime(0); //here you must put a time value that is before the wiggle.
yDiff = startPos - pos;
value + [0,yDiff,0];


Andrei
My Envato portfolio.


Return to posts index

Kevin Dearing
Re: Move one layer in opposite direction (in Y axis) of another layer
on Jan 6, 2020 at 9:00:57 pm

Thanks Andrei, that's basically what I've been trying to do but you really helped me with the object model a good bit. One thing I neglected to mention is a small (but important issue).. The front target's position is: [720, 540, 0]
And the back of the target is: [648, 316, 1]

So there's a delta of: [72, 224, 1]

So, now I have it so that the front (which is actually the "back" of the target) is bouncing with the wiggle, and the back (what I'm trying to apply the expression on to match the bouncing) is staying exactly where it started out.

The first expression below is giving me that... (Note, I decided that I want z to stay at 1 no matter what so...)


So, what I'm thinking is that I need to get the movement that the wiggle is introducing maybe by using ~.position.valueAtTime(time) - ~.position.valueAtTime(time -1) and adding that to my "front" layer..

I've tried a number of ways but I seem to be screwing that up! Maybe just brain dead at this point!

backOGPos=thisComp.layer("Tgt_Back").transform.position.valueAtTime(0);;
frontOGPos =thisComp.layer("Tgt_Front").transform.position.valueAtTime(0);

xDiff = backOGPos[0] - frontOGPos[0];
yDiff = backOGPos[1] - frontOGPos[1];
zDiff = backOGPos[2] - frontOGPos[2];

prevBkPos=thisComp.layer("Tgt_Back").transform.position.valueAtTime(time -1);
curBkPos=thisComp.layer("Tgt_Back").transform.position;


xDelta = prevBkPos[0] - curBkPos[0];
yDelta = prevBkPos[1] - curBkPos[1];
zDelta = prevBkPos[2] - curBkPos[2];

x = curBkPos[0] - xDiff + xDelta;
y= curBkPos[1] - yDiff + yDelta;
value = [x, y, 1];


Return to posts index


Andrei Popa
Re: Move one layer in opposite direction (in Y axis) of another layer
on Jan 6, 2020 at 11:01:04 pm

That is so overcomplicated...
Here is an expression if you want the x to modify same as front and y to the opposite(I thought you only wanted to move the y position from your initial post); In this expression, the "Tgt_Back" is the layer with the wiggle(i am guessing this one has the [720, 540, 0] values) and the "Tgt_Front" is the one that has inverted y. This is applied to "Tgt_Front" position.

initialPos = [720, 540, 0];
wigglePos = thisComp.layer("Tgt_Back").transform.position;
difference =[wigglePos[0]-initialPos[0], initialPos[1]-wigglePos[1],0] ;

value+difference


The idea is this. Value gives you the value of this property before the expression. So you only need to get the difference between the wiggle value and the initial position of the wiggle layer. And just add that to your value. If you want the same direction, you subtract the initial position from the wiggle. If you want different directions, you subtract the other way around(the third row in the expression).

I'm just trying to make you also understand how this work, not just use it.

The last row is something like [648, 316, 1] + [xRandomWiggle, -yRandomWiggle,0].

Andrei
My Envato portfolio.


Return to posts index

Kevin Dearing
Re: Move one layer in opposite direction (in Y axis) of another layer
on Jan 7, 2020 at 10:47:49 am

Thanks again for your time... I do tend to over complicate things from time to time.. And thank you for helping me to understand but it's not working.. Here's a small render of the issue I'm seeing with the below code...







initialPos = [720, 540, 0];
wigglePos = thisComp.layer("Tgt_Back").transform.position;
difference =[wigglePos[0]-initialPos[0], initialPos[1]-wigglePos[1],0] ;

value-difference


Return to posts index

Andrei Popa
Re: Move one layer in opposite direction (in Y axis) of another layer
on Jan 7, 2020 at 3:03:45 pm

I am just trying to understand your project now. So you have 2 layers. The face layer and the back layer(face of cards and back of cards).
You have a wiggle on one of them.

1.Which one has the wiggle?
2.Is your wiggle applied only to y position?
3.How does the second layer relate to this wiggle? Are they parented? Or is it just through my expression?

The way I think this should work is you take the main layer initial position. You calculate the difference created by the wiggle expression and then you add or subtract that difference, depending if you want it to move the same direction or contrary.

Andrei
My Envato portfolio.


Return to posts index


Kevin Dearing
Re: Move one layer in opposite direction (in Y axis) of another layer
on Jan 7, 2020 at 4:24:45 pm

Hi again. No, the comp with the target has a layer for the front, a layer for the back and a couple other layers. The front and the back have track mattes to create the holes. This comp is a layer in another comp, the main one. That is where the wiggle is, on the pre comp layer.

Originally I had the front and back parented thinking that would cover the wiggle but they were moving in opposite directions even then.

I had the wiggle on x y and z but the main concern is y.


Return to posts index

Kevin Dearing
Re: Move one layer in opposite direction (in Y axis) of another layer
on Jan 7, 2020 at 4:33:24 pm

I think the problem is that the back layer (with the face cards) had to be rotated on the y axis, 180 degrees (but like I mentioned before I used a flip effect) otherwise when the camera (in the main comp) came around it would be inverted. I am thinking when I get home I'll invert the image in photoshop shed replace it, remove the flip and hope that the wiggle moves everything the same way after that.


Return to posts index

Kevin Dearing
Re: Move one layer in opposite direction (in Y axis) of another layer
on Jan 7, 2020 at 7:23:05 pm

Well, that didn't solve the problem.. The wiggle on the precomp layer is still moving the 2 layers inside the precomp in different directions.. Strange..


Return to posts index


Kevin Dearing
Re: Move one layer in opposite direction (in Y axis) of another layer
on Jan 8, 2020 at 4:49:45 pm

Well I feel really stupid. I had the target precomp in my main comp twice.

Removing the duplicate and setting things back to normal (where in the precomp all of the layers were parented together) worked perfectly.. No expression was needed afterall (other than of course the wiggle that I put on there which was, in fact, working correctly)


Return to posts index

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