# Tutorial 186: Behaviors

## Joe Clay | Jul 26, 2019

In this week's After Effects tutorial, we explore building a Cinema 4D-like effector by setting up behaviors based on positioning of layers. In our first example of a very wildly inaccurate Apollo mission example, we use distance to illustrate a burn of the Command Module. I also mentioned that this was inspired by the 50th anniversary of the moon landing an the new Apollo 11 (2019) documentary. There's some amazing footage in there that was recovered, and I believe it's a lot of never-before-seen footage. It was painstakingly put together, and the result is excellent.

Anyway, we continue on to make objects scale as another object approaches and finally we make a space ship capable of matter rejection. What's that you ask? It's the ability to force objects to stay outside of a predefined perimeter. There's not asteroid that can touch our ship.

There are a ton of things that can be done with this technique. You're really only limited by your imagination and ability to code. We've already covered distance and angle, so you have a good base to start from!

### Expression Code

This is the more basic code from the tutorial. It covers distance only.

``````d = length(thisLayer.position, thisComp.layer('Moon').position);
s = ease(d, 100, 300, 80, 30);
[s, s];``````

This is the more complex code from the tutorial. It covers distance as well as angle.

``````r = effect("CC Sphere")("Radius") + thisComp.layer("Controller").effect("Shield Radius")("Slider");
ptA = thisLayer.position;
ptB = thisComp.layer('Zeus Orb').position;
d = length(ptA, ptB);
if(d < r) {
x = ptA[0] - ptB[0];
y = ptA[1] - ptB[1];
a = Math.atan2(y, x);
x = Math.cos(a);
y = Math.sin(a);
r = r - d;
value + [x*r, y*r];
} else {
value;
}``````

## Grab the Project Files

The best way to get our project files is to become a patron on Patreon. For \$5 a month, you get access to all of the tutorial project files we've made available as well as other monthly projects, rigs, R&D, elements, early product previews, and BTS content not available anywhere else! You can also purchase just this project file on our Gumroad Store if you would rather do that.

or