Learn how to create a line between 2 layers
If you are an absolute beginner, please start your learning by checking the essential resources below:
http://www.jjgifford.com/expressions/basics/index.html
https://helpx.adobe.com/after-effects/using/expression-basics.html
http://www.motionscript.com
1. Setup
- show the grid and the rulers, and activate snapping (from the “view” menu in the menu bar).
- draw a line shape from the center of the composition to +100px to the right; for example, if you work in 1920×1080, draw a line from [960,540] to [1060,540]
- rename shape layer to “line”
- Create 2 shape layers, conveniently renamed “from” and “to”, or import the assets that you want to link with a line, and make sure both layers anchor points are centered.
- Reposition one layer to the right, and the other to the left side of the composition.
2. Expressions
- Add an expression to shape layer(“line”)> shape 1> Position, to link the line start point to the Layer(“From”)
convert point space to composition space
Shape Layers transform controls are relative to the composition center,
[0,0] in the shape layer space is the center of the comp [960,540].
- Add an expression to shape layer(“line”)> shape 1> Scale, to evaluate the distance between the 2 objects
evaluates the distance between 2 points
var to = thisComp.layer(“to”).transform.position;
[length(from,to),value[0]]
- Add an expression to shape layer(“line”)> shape 1> Rotation, to orient the line to point to the destination object
Geometry: what is an arc tangent ?
Math.atan2(x,y) evaluates the counterclockwise angle in radians (not degrees)
between the positive X axis and the point (x, y).
radiansToDegrees() / degreesToRadians() convert angle measuring units
var to = thisComp.layer(“to”).transform.position;
radiansToDegrees( Math.atan2( from[1]-to[1], (from[0]-to[0]) ) )-180
Because Math.atan2() evaluates counterclockwise, substract to the result 180º
- pull out “Stroke 1” object out of “Shape 1” group and put it down in the stack, so that the stroke is rendered after transformation. You can also delete “Fill 1” object.
3. Fake Elasticity
- Add a zigzag object under the group, change Ridges per Segment to “1” and Points to “Smooth”
- Add an expression to shape layer(“line”)> ZigZag 1> Size, to determine the maximum size of the line and distort the line depending on the distance between the 2 layers
var to = thisComp.layer(“to”).transform.position;
var maxd = 960; //manually adjust the maximum length
(maxd-length(from,to))/4
ZigZag works like a sinusoid, distorting in both Y and -Y
- Add an expression to shape layer(“line”)> shape 1> Anchor Point, to shift the line position depending on the Zigzag distortion intensity
4. Alternative routes
The oldest method around is to use Effect> Generate> Beam and link Starting / Ending Points to both layers positions. This methods can be good enough if you need only a few lines and don’t need to stylize them. But if you have more than 5 lines then render time can increase dramatically.
Motion Boutique released a while ago Connect Layers, a free script originally made as a debug tool for Plexus, that works wonders to create rendered line connectors, elastic ropes and triangulations. But you will have to re-render keyframes each time you modify the animations.
Lastly, it is worth mentioning Lines creator, a quite expensive script ($25) that automatize the method explained in this post.
Hi,
Thanks for sharing your knowledge, very interesting and useful.
The ffx doesn’t show in AE CC?
LikeLike
Hello, thank you for commenting; it should work if you copied the FFX file in your AE presets folder (after renaming downloaded file to .zip and unzipping it, because wordpress won’t allow to host .FFX files).
LikeLike
It doesn’t work.
It seems FFX files are not backwards-compatible.
THX
LikeLike
Hi,
It’s a cool and useful way to create line instead of beam. And elasticity effect is similar to RubberHose!
I tried to add some extra control for selecting layer. If it was improper, I would remove it.
https://drive.google.com/file/d/0B7s8lxn6hUEQQWJTaFppMU5sb1U/view
LikeLike
Hi Yuan, thank you for your contribution
LikeLike
Is “http://www.motionscript.com” an Essential resource ? : ))))
Not really.
LikeLike
Dan Ebberts is a highly active member of the after effects pro users community, you can ask him anything about expressions and scripts on the creativecow, and his solution will blow your mind away
LikeLike