Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

Object rotating based on another object's position

New Here ,
Aug 23, 2020 Aug 23, 2020

Hello guys,

 

I've been trying to figure this problem out for the last several hours, and haven't found the solution yet...it sounds super simple but I can't solve it on my own, so asking if this is actually possible to do..

 

So I have multiple arrows on the comp and a null object, and what I'm trying to do is make the arrows face towards the null object continuously while it's moving. 

 

I tried to link each arrow's rotation expression to the position of the null object but had no luck, do you know how to approach this? Thank you so much in advance!

TOPICS
Expressions , FAQ , How to
7.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 23, 2020 Aug 23, 2020

You're kind of asking two different questions here, but the answer to both is that yes, it's possible.

Linking different property types is typically best accomplished using linear. In your case, you'd add this on the Rotation property on the arrows.

var pos = link to [one dimension of]Null's Position property ;
var posMin = enter the minimum position desired here ;
var posMax = enter the max position desired here ;
var rotMin = enter the max desired rotation here ;
var rotMax = enter the max desired r

...
Translate
Community Expert ,
Aug 23, 2020 Aug 23, 2020

You're kind of asking two different questions here, but the answer to both is that yes, it's possible.

Linking different property types is typically best accomplished using linear. In your case, you'd add this on the Rotation property on the arrows.

var pos = link to [one dimension of]Null's Position property ;
var posMin = enter the minimum position desired here ;
var posMax = enter the max position desired here ;
var rotMin = enter the max desired rotation here ;
var rotMax = enter the max desired rotation here ;
linear (pos, posMin, posMax, rotMin, rotMax)

You've now linked (a specific range of) the arrow's rotation to (a specific range of) the Null's Position.

That said, it doesn't sound like that's actually what you'd want here, as you'd have to tweak those values (probably by trial and error) for every arrow.

There's also a lookAt() function, which sounds like what you're actually looking for here.
Here's an old Creative Cow thread with some code for a 3d version, or a tutorial that looks like very much what you're after. 

[Edited to amend that you'd need to point this to only one dimension of the Null's position. I knew that in my brain, my fingers just chose not to type it!]

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 23, 2020 Aug 23, 2020

Thank you so much! This worked perfectly!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 23, 2020 Aug 23, 2020

If you want an arrow to point at another layer by far the easiest way to do that is with the vector math operator lookAt (fromPoint, toPoint). That will deliver a three-property array that can be used with orientation. If you want to use it on 2D layers you just have to pick the second property. Start with a horizontal arrow pointing to the right and the anchor point on the center of rotation. Name the layer you want the arrow to point at "Target" and use the following expressions for 2D or 3D layers:

 

 

// For 2D Layers
xVal = thisComp.layer("Target").transform.position[0] - position[0];
yVal = thisComp.layer("Target").transform.position[1] - position[1];
radians = Math.atan2(yVal, xVal);
radiansToDegrees(radians)

// for 3D layers
// Orientation
atPoint = thisComp.layer("Target").transform.position;
fromPoint = position;
lookAt(fromPoint, atPoint)

// Transform Rotation Y
-90

 

 

For the 3D layer, you'll have to set the Y rotation to -90º to get the arrow to orient to the camera If you add both expressions to the layer with the arrow you can save an animation preset that makes it easy to point an arrow at a target layer.

 

These are both foolproof solutions. The Linear expression that is shown will not work for rotation. You can't use a position array for either of the tMin and tMax variables in the linear method. They have to be single values. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 23, 2020 Aug 23, 2020

@Kyle_Hamrick: As far as I know the first three parameters of linear only work with numbers and not 2D or 3D arrays, so your approach should only work if you separate dimensions for the position and link to only X position or only Y-Position, right?

 

For the lookAt, iExpressions also has a handy expression for that

https://mamoworld.com/after-effects-expression/look-point-2d

 

 

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 24, 2020 Aug 24, 2020
LATEST

Absolutely. Oversight on my part - good catch!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines