Is it possible to just move a layer along one axis, eg x?

I need to move many layers individually in a 3D space, but only along one axis. It would be much quicker if I could lock all axis but one, and then move along that.


It's easy to do with a quick expression:

Alt/Option-click the stop watch for the position property. You'll see the default expression transform.position is automatically inserted. The position property is an array – it contains the X, Y and Z value components. We want to lock it so that only one of the values can change. So we have to pick the array apart into its components, and then create a new array using some constant values.

So say we want to lock the layer to movement only on the X axis. We'll use the X component of the transform.position array and then put in a constant value for the Y and Z components. Say the layer's Y position is 123 and its Z position is 345. We'd use this expression:

[transform.position[0], 123, 345]

note that the enclosing square brackets are part of the expression - they turn the three values back into an array. The bit where it says transform.position[0] selects just the first component of the array (just to be annoying, most computer languages count array components from 0, so the first component is [0], the second [1] and so on).

You could refine this to make the layer easier to edit:

[transform.position[0], transform.position.valueAtTime(0)[1], transform.position.valueAtTime(0)[2]]

here transform.position.valueAtTime(n) is a function that returns the value of the position property at time n. The round brackets are the input to the function, in this case the start of the comp or 0. Then as we want just one part of the position, we then use the square brackets to stipulate which bit: [1] for Y and [2] for Z (remember [1] means the second value in the array and [2] means the third). So the layer will be locked to the Y and Z position it has at the start of the comp, and will be free to move on the X position.

To do the same with the Y position or the Z, or the scale, or rotation or whatevs, you just use the same form, but change the array index (the number in the square brackets). So to lock the movement to only the Y axis:

[transform.position.valueAtTime(0)[0], transform.position[1], transform.position.valueAtTime(0)[2]]

or Z axis:

[transform.position.valueAtTime(0)[0], transform.position.valueAtTime(0)[1], transform.position[2]]

By now you should see the pattern.

Note that for 2D layers, the array only has two components, so you'd leave out the third part altogether, so to lock a 2D layer to the X axis you'd use:

[transform.position[0], transform.position.valueAtTime(0)[1]]

Expressions are your friend!

| improve this answer | |

You can move any object by dragging on the Position coordinates in the object's timeline.

enter image description here

Alternatively, you can constrain to a single dimension when moving an object in the canvas by putting your cursor over the appropriately coloured arrow (R, G, B, = x, y, z). Wait for your cursor to show a letter next to it, then drag the object.

enter image description here

| improve this answer | |
  • Ok, yes I know the canvas can move explicit in one direction. I thought it would be possible to explicit lock 2 axis, so that I can freehand move the elements without worrying about displacement. – membersound Dec 30 '14 at 11:43
  • 1
    I don't think it's possible.. – tomh Dec 30 '14 at 11:47

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.