Answers.Body: <p>You can move any object by dragging on the Position coordinates in the object's timeline.</p>
  
  <p><img src="https://i.sstatic.net/PPLJ2.png" alt="enter image description here"></p>
  
  <p>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.</p>
  
  <p><img src="https://i.sstatic.net/NhHes.jpg" alt="enter image description here"></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-30T11:43:10.163Z
Answers.Text: 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.
Answers.UserDisplayName: membersound
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-30T11:47:10.983Z
Answers.Text: I don't think it's possible..
Answers.UserDisplayName: tomh
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-30T11:33:33.153Z
Answers.LastActivityDate: 2014-12-30T11:46:49.617Z
Answers.LastEditDate: 2014-12-30T11:46:49.617Z
Answers.UserDisplayName: tomh
Answers.Body: <p>You can also just separate the dimensions, add an expression to each axis you want to lock and type in 0 (or wherever you want the position locked) in the expression field.
  <a href="https://i.sstatic.net/YIxYG.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/YIxYG.png" alt="Here you see the z axis is locked" /></a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-07-12T14:46:24.263Z
Answers.LastActivityDate: 2022-07-12T14:46:24.263Z
Answers.UserDisplayName: Kev
Answers.Body: <p>It's easy to do with a quick expression:</p>
  
  <p><kbd>Alt/Option</kbd>-click the stop watch for the position property. You'll see the default expression <strong><em>transform.position</em></strong> 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.</p>
  
  <p>So say we want to lock the layer to movement only on the X axis. We'll use the X component of the <strong><em>transform.position</em></strong> 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:</p>
  
  <pre><code>[transform.position[0], 123, 345]
  </code></pre>
  
  <p>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 <strong><em>transform.position[0]</em></strong> selects just the first component of the array (just to be annoying, most computer languages <a href="https://stackoverflow.com/questions/7320686/why-does-the-indexing-start-with-zero-in-c">count array components from 0</a>, so the first component is <strong>[0]</strong>, the second <strong>[1]</strong> and so on).</p>
  
  <p>You could refine this to make the layer easier to edit:</p>
  
  <pre><code>[transform.position[0], transform.position.valueAtTime(0)[1], transform.position.valueAtTime(0)[2]]
  </code></pre>
  
  <p>here <strong><em>transform.position.valueAtTime(n)</em></strong> is a function that returns the value of the position property at time <em>n</em>. 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: <strong><em>[1]</em></strong> for Y and <strong><em>[2]</em></strong> for Z (remember <strong><em>[1]</em></strong> means the second value in the array and <strong><em>[2]</em></strong> 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.</p>
  
  <p>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:</p>
  
  <pre><code>[transform.position.valueAtTime(0)[0], transform.position[1], transform.position.valueAtTime(0)[2]]
  </code></pre>
  
  <p>or Z axis:</p>
  
  <pre><code>[transform.position.valueAtTime(0)[0], transform.position.valueAtTime(0)[1], transform.position[2]]
  </code></pre>
  
  <p>By now you should see the pattern.</p>
  
  <p>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:</p>
  
  <pre><code>[transform.position[0], transform.position.valueAtTime(0)[1]]
  </code></pre>
  
  <p>Expressions are your friend!</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-30T13:10:25.163Z
Answers.LastActivityDate: 2014-12-31T01:20:23.933Z
Answers.LastEditDate: 2017-05-23T12:40:36.170Z
Answers.UserDisplayName: stib
Body: <p>Is it possible to just move a layer along one axis, eg <code>x</code>?</p>
  
  <p>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.</p>
  
Tags: <after-effects>
Title: How to move a layer only in one direction?
UserDisplayName: membersound
ThreadText: # How to move a layer only in one direction?
  
  (Asked by: username_0 on 2014-12-30)
  
  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.
  
  **Tags:** after-effects
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_3 on 2014-12-30. Score: 2 | Accepted answer
  
  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](https://stackoverflow.com/questions/7320686/why-does-the-indexing-start-with-zero-in-c), 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!
  
  
  ---
  
  ### Answer by username_1 on 2014-12-30. Score: 2
  
  You can move any object by dragging on the Position coordinates in the object's timeline.
  
  ![enter image description here](https://i.sstatic.net/PPLJ2.png)
  
  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](https://i.sstatic.net/NhHes.jpg)
  
  > **Comments:**
  > **username_0**: 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.  
  > **username_1**: I don't think it's possible..  
  
  ---
  
  ### Answer by username_2 on 2022-07-12. Score: 1
  
  You can also just separate the dimensions, add an expression to each axis you want to lock and type in 0 (or wherever you want the position locked) in the expression field.
  [![Here you see the z axis is locked](https://i.sstatic.net/YIxYG.png)](https://i.sstatic.net/YIxYG.png)
  
  
  ---
  
  