A 2D lookAt() function

Moderators: Disciple, zlovatt

Post Reply
Posts: 20
Joined: December 10th, 2006, 10:23 pm

For 2D, the lookAt() function in After Effects’ expression language doesn’t work as expected. When the looked-at point is below the looking-from point the direction reverses. This has been driving me nuts for years, so to save me having to go back to my high school trigonometry, I've created a function to replace the built-in lookAt() function:

Code: Select all

function lookAtMe(fromPt, toPt){
    lkAt = lookAt(fromPt, toPt);
    if (toPt[1] > fromPt[1]){
        return 180-lkAt[1];
    } else {
        return lkAt[1];
//implement the function
p0= transform.position; //look from point
p1=thisComp.layer("some other layer").transform.position; //looked-at point
lookAtMe(p0, p1)
More details on my blog.
Post Reply