3 Replies Latest reply on Sep 9, 2016 7:52 AM by Rick Gerard

# rotate object to follow null

I'm trying to recreate this effect in AE.

I want a grid of lines to auto-orient to always be pointing at a moveable point (null, shape, whatever works.)

For the life of me I can't get the expression to coordinate.

Please help!

- E

• ###### 1. Re: rotate object to follow null

If you are playing with lookAt and 3D layers then this will work:

lookAt(position, thisComp.layer("leader").position)

if applied to the layer's orientation and your null is named "leader'

It will take some figuring on my part to make looAt work with 2D layers.

I would suggest you take a look at Dan Ebberts motion script site -- especially these pages:

Creating Trails - MotionScript.com

auto orient y only - Dan Ebberts's Expressioneering Design Guide

Case Study: 2D Auto Orientation

The last link is probably a start at what you want. If your null was named leader the expression you would start with would look like this:

L = thisComp.layer("leader");

u = L.toWorldVec([1,0]);

radiansToDegrees(Math.atan2(u[1],u[0]))

But if that is not what you need please include a detailed description and/or copy and paste a full resolution screenshot in the reply field on the forum so we can better help you find a solution.

(Edit)

Finally had a moment

If your null is named leader then this expression will always point a layer at the null.

this_point = thisComp.layer("leader").position;

that_point = position;

delta=sub(this_point, that_point);

angle=Math.atan2(delta[1], delta[0]);

ang = radians_to_degrees(angle);

(ang)%360

3 people found this helpful
• ###### 2. Re: rotate object to follow null

Thank you so much Rick. You nailed it.

• ###### 3. Re: rotate object to follow null

With a little more work on the basic idea you could define a radius of influence so the pull of the layers toward the follow null was proportional. You would do that by using the length method and set up a multiplier based on the distance so if the leader was more than something like 300 pixels there would be no influence on the angle but as it moved closer to the layer the attraction to the leader would increase so it would point directly at the leader if the distance was less than 200 pixels. It's all basic math. I'll leave you to figure that one out.