Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Follow object expression

  • Follow object expression

    Posted by Alistair David on April 12, 2007 at 4:06 am

    Hi everyone,
    Basically I am looking for an expression that will make my eyes follow a layer,i.e the head stays still while a plate of food is tempted infront of it with only the eyes position moving in accordance to where the plate of food is.

    I found this
    https://www.adobe.com/designcenter/aftereffects/articles/aft6pointat.html
    but it wont work, error messages pop up (and its not just me it wont work with other people)

    Preferably id like an expression that doesnt work of displace the anchor point and adjusting the rotation.Can I instead have the eyeballs postion follow the food but without them goin outside the boundary of the sockets?

    I cant think of a way to do this!!

    plaese help

    Cheers
    Al

    Lasse Gjertsen replied 14 years, 2 months ago 4 Members · 4 Replies
  • 4 Replies
  • Mike Clasby

    April 12, 2007 at 7:31 am

    OK, did you copy/paste the expression from the tut? I tried the link to the tut you gave and had the same problem with error messages, for the last line, a syntax problem. I think its an html copy/paste thing, because if you retype the last line below, then delete the pasted last line, the expression works, at least it did for me.

    This expression works:

    src = thisComp.layer(“food”);
    v = (position – src.position);
    comp = Math.atan2(v[1], v[0]);
    radiansToDegrees(comp) – 90;

    If you are using AE 5.5 you might still have a problem, “thisComp” needs to be changed to “this_comp”.

    As far as the eyes rotating out of the socket, it all depends where the anchor point for each eye is. Move the anchor point closer to the part that moves for less range (keeps it in the socket).

  • Filip Vandueren

    April 12, 2007 at 11:10 am

    Apply this to the position property rather than the rotation:

    socketRadius= 20; // change this depending on the size of your eye-socket
    multiplier= 0.1; // change this to determine how closely the eye follows the food

    src = thisComp.layer("food");
    v = (toComp(anchorPoint) - src.toComp(src.anchorPoint));

    d= Math.sqrt(v[0]*v[0] + v[1]*v[1]); // distance to food, Pythagoras
    r = Math.atan2(v[1], v[0]); // angle to food

    [Math.cos(r),Math.sin(r)] * Math.min(d*multiplier,socketRadius);

    the multiplier determines that if the food is 100 pixels below the eye, the eye ball will move down 10 pixels (100*0.1) but never more than socketRadius.

    I haven’t tested this yet though.

  • Filip Vandueren

    April 12, 2007 at 2:10 pm

    I’ve tested and the final line should read like this:


    socketRadius= 25; // change this depending on the size of your eye-socket
    multiplier= 0.2; // change this to determine how closely the eye follows the food

    src = thisComp.layer("food");
    v = (toComp(anchorPoint) - src.toComp(src.anchorPoint));

    d= Math.sqrt(v[0]*v[0] + v[1]*v[1]); // distance to food, Pythagoras
    r = Math.atan2(v[1], v[0]); // angle to food

    value - [Math.cos(r),Math.sin(r)] * Math.min(d*multiplier,socketRadius);

  • Lasse Gjertsen

    March 13, 2012 at 2:47 pm

    (I know this post is pretty old, but I’ll post some expressions here if anybody else is trying to find answers.)

    I use these expressions to control my characters eyes. They are based on Daniels Gies great work.

    The first expression (PUPIL FOLLOW OBJECT) is a setup for the pupil layer to move around in accordance to the motion of the OBJECT.

    The second expression (PUPIL FOCUS) makes the pupils move closer and further apart (by manipulating OBJECT’s x-scale) and move them contrarily vertically (by manipulating OBJECT’s y-scale).

    If the pupils and eyes are mounted on a head, and this head moves or rotates, the eyes will be stuck in the same position relative to the head. In other words; they will not point towards the OBJECT any more! Therefore it might be a good idea to mount the OBJECT to the head to always make the eyes positions relative to the OBJECT.

    So it’s not perfect, but it’s at least a much easier way of controlling the eyes of your character.

    // PUPIL FOLLOW OBJECT - Copy expression to pupil-layer/Transform/Position
    // OBJECT is name of layer to follow, replace with correct name
    a=thisComp.layer("OBJECT").transform.position;
    transform.position+a*5/30; //Multiplier, calibrate to you liking
    // Place OBJECT right between the eyes and move pupils to correct position

    // PUPIL FOCUS - Copy expression to pupil-layer/Effects/Transform/Position
    // Set pupil layer/Effects/Transform/Anchor Point to 0,0 to reset position
    // OBJECT is name of layer to follow; replace with correct name
    // DISTANCE is a Slider Controller in OBJECT-layer; replace with correct names
    a=thisComp.layer("OBJECT").transform.scale[0]; // Link to OBJECT x-scale,
    b=linear(a, 100, 300, [30,0], [-30, 0]); // Calibrate to your likings
    c=thisComp.layer("OBJECT").transform.scale[1]; // Link to OBJECT y-scale
    d=linear(c, 100, 300, [0,30], [0, -30]); // Calibrate to your likings
    b+d // For opposite eye: -b+-d

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy