ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Aim Constraint

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
William Anugerah
Aim Constraint
on Feb 6, 2017 at 10:22:38 am

Hello and good day to all,

This time I'd like to ask if anyone knows the script required to create a sort of "aim constraint" in After Effects.

So what I mean is this: Two objects, when the "controller" object (red null) is moved, the yellow null object will rotate on its axis to orient itself towards the controller.

Seems like it should've been simple but I can't figure out how to make it work.

Thank you in advance!

Return to posts index

Kevin Camp
Re: Aim Constraint
on Feb 6, 2017 at 8:32:34 pm

for 2d layers, this should work:
target = thisComp.layer("Null 1"); // set this to the layer to aim at
p = position - target.position;
radiansToDegrees( Math.atan2( p[1], p[0] ) )

for 3d layers you can use lookAt() on the orientation of the layer:
target = thisComp.layer("Null 1");// set this to the layer to aim at
lookAt( position, target.position )

Kevin Camp
Art Director

Return to posts index

Donutz Mar
Re: Aim Constraint
on Sep 16, 2017 at 7:38:32 pm

Hi! This seems a good solution ☺

Good luck!

Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 All Rights Reserved