AE Tips and Tricks

Monday, July 16, 2007

Flying A Kite

Here's a simple project using expressions to tie a string to a kite and fly it around in 3D space. The point one layer at another then adjust the X scale so that the layer always reaches the target. You can apply this technique to other projects. I hope you enjoy this tutorial.

I created a layer called String and a layer called Kite. I drew an open mask on the String layer that shaped a gentle arc, added the Stroke effect with a width of 3 pixels and Paint on Transparent selected. The stroke goes from the left edge to the right edge of the String layer, and that's important. The String layer is slightly narrower than the comp to make it easy to work with. The last step with the String layer is to move the anchor point to the left most vertice point of the mask at exactly an X value of 0. this is also important. Both layers are converted to 3D.

The Kite layer is simply a square solid with a kite shaped mask and the anchor point moved to where the string would attach.

The following expressions are added to the string layer:
String Scale:
point1 = position;
point2 = thisComp.layer("Kite").position;
L = length(point1, point2);
w = thisLayer.width;
r = L/w*100;

[r, value[1], value [2]]
String Orientation:
t = thisComp.layer("Kite");
l = thisComp.layer("String");

fromPoint = l.position
atPoint = t.position
lookAt(fromPoint, atPoint)
If you look carefully at the language you'll see that I'm calculating the distance between the anchor points and then dividing the distance by the layer width and multiplying that number by 100 to arrive at a scale factor so that the String layer is always the same length as the distance between the end of the string and the kite. The Orientation part of the expression simply points the string at the kite. There is one problem that must be overome. The string layer is perpendicular to the Kite so, and this part is important, the Y rotation must be changed to -90 to get things back to normal. This isn't another expression, it's just a value you put in.

The Kite layer also needs an expression to point the kite at the end of the string. The Kite orientation expression is basically the same as the String Orientation expression with definitions for the from and at point reversed. It looks like this:
Kite Orientation:
t = thisComp.layer("String");
l = thisComp.layer("String");

fromPoint = t.toWorld(position);
atPoint = l.toWorld(thisComp.layer("String").anchorPoint);
lookAt(fromPoint, atPoint)
Now the kite can be moved around and the string will follow.
You should find a sample 6.5 comp Here. I added a coupple of wiggle expressions to move the kite around. It was a fun way to spend a half hour this evening.


Post a Comment

<< Home