Answers.Body: <p>Expressions are you friend. Honestly I don't understand how anyone use AE without using expressions. To make the size of a rectangle shape follow a mouse you could do this.</p>
  
  <p>Parent the mouse and rectangle to a null, with the top left corner of the rectangle aligned with the null. On the size property <kbd>alt/option</kbd>-click the stopwatch to open the expressions editor.</p>
  
  <p>Delete what's there, and drag the pickwhip (the blue curly thing) to select the position of the cursor layer. </p>
  
  <p><a href="https://i.sstatic.net/m6ivI.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/m6ivI.png" alt="enter image description here"></a></p>
  
  <p>the size property will now look like:</p>
  
  <pre><code>thisComp.layer("cursor").transform.position
  </code></pre>
  
  <p>(if your cursor layer is called "cursor"). Now when you move the cursor the rectangle will scale to match the movement. But there's a problem, it scales from the middle, so you can add an offset to its position to make sure it lines up correctly. This time we use a bit of maths as well. On the position property of the rectangle path (not the position property of the layer) <kbd>alt/option</kbd>-click the stopwatch and drag the pickwhip to the size property of the rectangle, and then divide that value by 2. It will look like:</p>
  
  <pre><code>content("Rectangle 1").content("Rectangle Path 1").size/2
  </code></pre>
  
  <p>Now your rectangle should resize as if it's beign dragged by the cursor. You might have to manually drag the layer to line up perfectly. You can use more javascript to make the layer start and stop following the mouse.</p>
  
  <p><a href="https://helpx.adobe.com/after-effects/using/expression-basics.html" rel="nofollow noreferrer">Go learn expressions</a>. As a bonus (or perhaps as a negative) you get to learn javascript, a ubiquitous computer language.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-24T10:42:04.177Z
Answers.Text: yeah, I also love expressions :D
  How would you go about making it stop? Cutting up the layer using cmd/ctrl + shift + d? Or is there something to do just that?
  Also the whole Null thing would mean the rectangles follow my cursor before the animation takes place? Or when I have multiple rectangles, would I have to use multiple nulls parented?
  Also thanks for your help!
Answers.UserDisplayName: CrazyQwert
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-24T12:46:59.203Z
Answers.Text: You can use expressions to make it start and stop. For example a technique I often use is to have the expression start after the last keyframe. You do that with something like `if (time>foo.bar.key(foo.bar.numkeys).time){ <whatever> }` the code inside the curly braces will only get executed if the time is later than the last keyframe for the foo.bar property.
Answers.UserDisplayName: stib
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-24T12:50:47.037Z
Answers.Text: You could also use another property to turn the expression on or off, e.g. a slider in an **Expression Control** effect: `if (effect("Slider Control")("Slider") > someValue){ <whatevs> }` would execute the code only when the slider value was above someValue.
Answers.UserDisplayName: stib
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-17T12:11:38.810Z
Answers.LastActivityDate: 2016-11-17T12:11:38.810Z
Answers.UserDisplayName: stib
Body: <p>I am currently trying to create some kind of drag and drop as well as a drag and select animation in after effects. The latter one is supposed to be looking something like this in the end:</p>
  
  <p><a href="https://i.sstatic.net/shN7k.gif" rel="nofollow noreferrer"><img src="https://i.sstatic.net/shN7k.gif" alt="enter image description here"></a></p>
  
  <p>(this animation is from adobe themselves, showing how to make stuff pixel-perfect in illustrator and can be found here: <a href="https://helpx.adobe.com/illustrator/how-to/pixel-perfect.html" rel="nofollow noreferrer">https://helpx.adobe.com/illustrator/how-to/pixel-perfect.html</a>)</p>
  
  <p>My problem is, that (1) I have have no idea how to make an object follow the animation of another object but only for a certain time. I mean, there is parenting, but I obviously just want the object to follow my cursor-object as long as it is in "clicked state" and not during the whole animation. I hope that makes sense ...</p>
  
  <p>Also (2) I have no Idea how to let an anchor point of a rectangle follow another object.</p>
  
  <p>My way of doing such an animation would be animating each object independently, but it always gets messy lining those animations up, especially when I for example change the speed of one of these animations in question, because I then will have to redo all the lining up again. There has to be an easier way!</p>
  
  <p>Please let me know if you either know the answer yourself or a tutorial that can help me with this.</p>
  
  <p>Kind regards,
  Arvid</p>
  
Tags: <after-effects><animation>
Title: Mouse drag and drop / drag to select animation in after effects
UserDisplayName: CrazyQwert
ThreadText: # Mouse drag and drop / drag to select animation in after effects
  
  (Asked by: username_0 on 2016-11-13)
  
  I am currently trying to create some kind of drag and drop as well as a drag and select animation in after effects. The latter one is supposed to be looking something like this in the end:
  
  [![enter image description here](https://i.sstatic.net/shN7k.gif)](https://i.sstatic.net/shN7k.gif)
  
  (this animation is from adobe themselves, showing how to make stuff pixel-perfect in illustrator and can be found here: <https://helpx.adobe.com/illustrator/how-to/pixel-perfect.html>)
  
  My problem is, that (1) I have have no idea how to make an object follow the animation of another object but only for a certain time. I mean, there is parenting, but I obviously just want the object to follow my cursor-object as long as it is in "clicked state" and not during the whole animation. I hope that makes sense ...
  
  Also (2) I have no Idea how to let an anchor point of a rectangle follow another object.
  
  My way of doing such an animation would be animating each object independently, but it always gets messy lining those animations up, especially when I for example change the speed of one of these animations in question, because I then will have to redo all the lining up again. There has to be an easier way!
  
  Please let me know if you either know the answer yourself or a tutorial that can help me with this.
  
  Kind regards,
  Arvid
  
  **Tags:** after-effects, animation
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-11-17. Score: 1 | Accepted answer
  
  Expressions are you friend. Honestly I don't understand how anyone use AE without using expressions. To make the size of a rectangle shape follow a mouse you could do this.
  
  Parent the mouse and rectangle to a null, with the top left corner of the rectangle aligned with the null. On the size property `alt/option`-click the stopwatch to open the expressions editor.
  
  Delete what's there, and drag the pickwhip (the blue curly thing) to select the position of the cursor layer.
  
  [![enter image description here](https://i.sstatic.net/m6ivI.png)](https://i.sstatic.net/m6ivI.png)
  
  the size property will now look like:
  
  ```
  thisComp.layer("cursor").transform.position
  
  ```
  
  (if your cursor layer is called "cursor"). Now when you move the cursor the rectangle will scale to match the movement. But there's a problem, it scales from the middle, so you can add an offset to its position to make sure it lines up correctly. This time we use a bit of maths as well. On the position property of the rectangle path (not the position property of the layer) `alt/option`-click the stopwatch and drag the pickwhip to the size property of the rectangle, and then divide that value by 2. It will look like:
  
  ```
  content("Rectangle 1").content("Rectangle Path 1").size/2
  
  ```
  
  Now your rectangle should resize as if it's beign dragged by the cursor. You might have to manually drag the layer to line up perfectly. You can use more javascript to make the layer start and stop following the mouse.
  
  [Go learn expressions](https://helpx.adobe.com/after-effects/using/expression-basics.html). As a bonus (or perhaps as a negative) you get to learn javascript, a ubiquitous computer language.
  
  > **Comments:**
  > **username_0**: yeah, I also love expressions :D How would you go about making it stop? Cutting up the layer using cmd/ctrl + shift + d? Or is there something to do just that? Also the whole Null thing would mean the rectangles follow my cursor before the animation takes place? Or when I have multiple rectangles, would I have to use multiple nulls parented? Also thanks for your help!  
  > **username_1**: You can use expressions to make it start and stop. For example a technique I often use is to have the expression start after the last keyframe. You do that with something like `if (time>foo.bar.key(foo.bar.numkeys).time){ <whatever> }` the code inside the curly braces will only get executed if the time is later than the last keyframe for the foo.bar property.  
  > **username_1**: You could also use another property to turn the expression on or off, e.g. a slider in an **Expression Control** effect: `if (effect("Slider Control")("Slider") > someValue){ <whatevs> }` would execute the code only when the slider value was above someValue.  
  
  ---
  
  