Moderators: Disciple, zlovatt

Topic Author
Posts: 15
Joined: Sun Dec 10, 2006 10:23 pm

A 2D lookAt() function

Wed Oct 21, 2015 7:47 am

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:

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.

Who is online

Users browsing this forum: No registered users and 2 guests