Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Rotate away from Camera problem

  • Rotate away from Camera problem

    Posted by Brian Charles on March 25, 2008 at 12:54 am

    I’m hoping that someone can spot the error in my script. I have series of layers that rotate as the camera approaches. Some should rotate clockwise others counter clockwise. The start and end rotations as well as the angle are set by expression controls on a master layer. My problem is that the counter clockwise and clockwise rotations are not in sync. I’ve brute forced a solution but it bugs me that I don’t see the reason I need to. There must be an error in the script that eludes me.

    Here is my script for the cc rotation (applied to the Y axis):

    startR =effect(“Rotation Start Distance”)(“Slider”);// start rotation in pixels from camera
    endR = effect(“Rotation End Distance”)(“Slider”); // end rotation in pixels from camera
    C= thisComp.activeCamera;
    P = length(toWorld(anchorPoint),C.toWorld([0,0,0]));
    endAngle = effect(“Angle Control”)(“Angle”);
    ease(P,startR,endR,endAngle,0)

    The clockwise script:
    //ROTATE CLOCKWISE
    startR =thisComp.layer(“Master”).effect(“Rotation Start Distance”)(“Slider”) + 100;// start rotation in pixels from camera
    endR = thisComp.layer(“Master”).effect(“Rotation End Distance”)(“Slider”); // end rotation in pixels from camera
    C= thisComp.activeCamera;
    P = length(toWorld(anchorPoint),C.toWorld([0,0,0]));
    endAngle = (thisComp.layer(“Master”).effect(“Angle Control”)(“Angle”)*-1)// INVERT VALUE;
    ease(P,startR,endR,endAngle,0)

    You’ll note that I’ve forced the clockwise to behave by adding 100 to the startR value. I have no idea why I need to…

    Brian Charles replied 18 years, 1 month ago 3 Members · 10 Replies
  • 10 Replies
  • Brian Charles

    March 25, 2008 at 1:04 am

    After more experimentation it seems that the Camera’s X position influences when the rotation occurs, which leads me to believe that the position value P is not based on the Camera’s Z pos but some absolute world / camera function.

  • Brian Charles

    March 25, 2008 at 2:31 am

    No I’m sure it has to do with layer space transforms. I’ve read the expression reference but don’t understand it…

  • Dan Ebberts

    March 25, 2008 at 3:22 am

    Your expressions work fine for me. They’re based on the layer’s distance from the camera. Is that not what you wanted?

    Dan

  • Brian Charles

    March 25, 2008 at 4:04 am

    Dan, thanks for your attention. They work but the clockwise ones rotate out of sync.

    I have rows of images side-by-side, offset on the z axis.

    As the camera moves towards them, they swing open like doors and the camera passes through to the next set of doors.

    I’ve moved the layer anchor points to their respective outside edge (where they would be hinged). The right hand ones should move clockwise as the left hand ones move counter clockwise.

    Without that brute force, the right hand ones lag approximately 10 frames.

    Could it be that the layer transforms are different since the anchor points are in opposite locations?

  • Dan Ebberts

    March 25, 2008 at 4:51 am

    Assuming that your camera is moving only in the z direction, and the anchor points of the left and right doors are exactly the same distance from the camera, they should rotate at the same time. The doors’ anchor points should have the same y value and be the same distance on the x axis from the camera’s x position. If you move the camera so that it gets closer to one door than the other, all bets are off. 🙂

    Dan

  • Brian Charles

    March 25, 2008 at 5:06 am

    You’ve described exactly what I intend.

    The layers are different widths so their anchor points are equidistant from the camera on the Z axis but not on the Y axis.

    Can the script accommodate the width difference? (layer.width)??

  • Dan Ebberts

    March 25, 2008 at 1:39 pm

    If you want it to only consider z distance you could do something like this:

    startR =effect(“Rotation Start Distance”)(“Slider”);// start rotation in pixels from camera
    endR = effect(“Rotation End Distance”)(“Slider”); // end rotation in pixels from camera
    C= thisComp.activeCamera;
    P = toWorld(anchorPoint)[2] – C.toWorld([0,0,0])[2];
    endAngle = effect(“Angle Control”)(“Angle”);
    ease(P,startR,endR,endAngle,0)

    Dan

  • Brian Charles

    March 25, 2008 at 3:32 pm

    Thanks Dan. I’ll give that a try.

  • Darby Edelen

    March 25, 2008 at 7:19 pm

    The problem you’re facing is the same problem that Dan looks at in his Auto Focus expression on https://www.motionscript.com.

    Basically, the length() function in your expression gives you the distance between the camera and the anchor point of the layer, but consider that the distance is derived from a three dimensional vector where the X, Y and Z positions of both the camera and the layer come into play.

    The distance between something sitting exactly 900 pixels in front of the camera ([0,0,900] relative to the camera) is 900 pixels, but the distance between something sitting 900 pixels in front of the camera and 300 pixels to the left of the camera ([-300,0,900] relative to the camera) is 948.68 pixels.

    Personally, I would suggest simply inverting the rotation of the other side of the door to fix this problem. Although it might not work in every case, it is simple.

    Darby Edelen
    Designer
    Left Coast Digital
    Santa Cruz, CA

  • Brian Charles

    March 25, 2008 at 8:06 pm

    Dan and Darby thank you both. Dan’s solution worked for me, and thanks to Darby I now understand the problem clearly.

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