2

I have a 3D position property linked with another composition. I want the z-axis to have an offset in the linked expression. But how can I apply an offset just to one axis?

The current expression of the 3D position:

comp("Main COMP").layer("text").transform.position
4

The position property is an array, which is a container with a number of components in it, in this case the three position values: x, y and z. To specify an array you use this notation foo = [A,B,C] where A, B and C are the individual values – constants, variables, whatevs. TL;DR to create an array you put a number of comma-separated values in square brackets.

Conversely you can access any of the components of an array using this notation: foo[n] where foo is the name of the variable, and n is the index of the component you want. Note that the index starts at 0, so to get the first component of the array you would use foo[0], the second foo[1] and so on. Arrays can also be multi-dimensional, so the address could be foo[0][5][99] for a three dimensional array. But you probably don't need to worry about that at this point.

In your case you want just the third component to have the offset. So you need to unpick the original array using the foo[0], foo[1]… notation and then put it back together as an array using the [A,B,C] notation. Thus:

thePos = comp("Main COMP").layer("text").transform.position;
[thePos[0], thePos[1], thePos[2]+offset]

where offset is whatever your offset is, obviously.

The first line is just for convenience - it assigns the position property as the value of the variable myPos. You could do it all on one line, but it gets a bit hard to read:

[comp("Main COMP").layer("text").transform.position[0], comp("Main COMP").layer("text").transform.position[1], comp("Main COMP").layer("text").transform.position[2]+offset]
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.