A simple Position change to a 3D layer

Scripting for After Effects

A simple Position change to a 3D layer

Hey all -
I'm very new to expressions, although I was an Actionscript developer in another life. It's very frustrating to me when I feel like something very simple should work, so instead of banging my head against my desk, I thought I'd turn to my favorite community.

I want to change the x, y, and z position values of a comp.

I need it's position to match a nested comp's position -- with some static offsets.

Eventually, I'll add some math that moves its y position at a fraction of the speed... but first, I have to get this syntax right.

************************
THIS WORKS:
comp("BG").layer("BG_mover").transform.position + [-1120,-10564,-3000]

************************
THIS DOES NOT WORK:
x=comp("BG").layer("BG_mover").transform.position.value[0]
y=comp("BG").layer("BG_mover").transform.position.value[1]
z=comp("BG").layer("BG_mover").transform.position.value[2]

x_offset = -1120
y_offset = -10564
z_offset = -3000

newX = x + x_offset
newY = y + y_offset
newZ = z + z_offset

[newX, newY, newZ]

************************
The error I get:
"Error at 11 in property 'Position' of layer 105 ("FG") in comp 'MAIN'.
property or method name 'undefined' in Class 'Number' is missing or does not exist. It may have been renamed, moved, deleted, or the name may have been mistyped."

I tried removing ".value"
I tried simplifying in a bunch of ways.
Someone please tell me that I'm missing something simple.

andynick

Posts: 12
Joined: 06/1/2011, 1:55 pm

Re: A simple Position change to a 3D layer

well i should probably direct you to the 3d stroke expression tutorial found on this same site...but its really just 10 minutes of setup then he gives us this expression..
x=(thisComp.layer("Null 1").transform.position[0]-thisComp.width/2;
x/thisComp.width

y=(thisComp.layer("Null 1").transform.position[1]-thisComp.height/2;
y/thisComp.width

z=(thisComp.layer("Null 1").transform.position[2];
z/thisComp.width

I dont know anything about expressions but yours looked like this so i thought it might help..
ender772

Posts: 308
Joined: 04/19/2013, 3:52 pm

Re: A simple Position change to a 3D layer

It looks like as soon as there's a line with more going on than just setting a fixed value as a variable, you have to end the line with a semi-colon. So this works:

Code: Select all
`x=comp("BG").layer("BG_mover").transform.position.value[0];y=comp("BG").layer("BG_mover").transform.position.value[1];z=comp("BG").layer("BG_mover").transform.position.value[2];x_offset = -10y_offset = -100z_offset = -300newX = x + x_offset;newY = y + y_offset;newZ = z + z_offset;[newX, newY, newZ]`
Laserschwert

Posts: 38
Joined: 09/8/2008, 2:30 pm

Re: A simple Position change to a 3D layer

Much appreciated. In Actionscript, semicolons are optional --- so I have some baaaaaad habits to break.

Thanks again!
andynick

Posts: 12
Joined: 06/1/2011, 1:55 pm