Mouse drag and drop / drag to select animation in after effects 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:



(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
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. 



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. As a bonus (or perhaps as a negative) you get to learn javascript, a ubiquitous computer language.