Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions how to orient-to-camera using only 1 axis

  • how to orient-to-camera using only 1 axis

    Posted by Randy Mcwilson on February 21, 2007 at 1:48 am

    We are trying to animate a fly by “3D” map with a hi-res image of the USA with city names that are floating above the surface at 90 degrees to it. We want these city names to always rotate on the Y axis to stay oriented towards the camera. But when orient-towards-camera is selected it will effect all 3 axes (as it should). Is it perhaps possible to use an expression to keep the Y rotation aligned with the relative position of the flying camera?

    Thanks in advance
    Randy

    Dan Ebberts replied 19 years, 5 months ago 2 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    February 21, 2007 at 2:09 am

    Try this on your y rotation property:

    delta = toWorld(anchorPoint) – thisComp.activeCamera.toWorld([0,0,0]);
    radiansToDegrees(Math.atan2(delta[0],delta[2]))

    Dan

  • Randy Mcwilson

    February 21, 2007 at 2:28 am

    Dan:

    You are amazing. Could you possibly do a small operand-by-operand explanation. It works beautifully

    Randy

  • Dan Ebberts

    February 21, 2007 at 3:41 am

    OK – but it’s a little hard to describe without a diagram.

    delta = toWorld(anchorPoint) – thisComp.activeCamera.toWorld([0,0,0]);

    This line just calculates the vector (distance and direction) from the camera to the layer. It looks complicated because it’s using the toWorld() layer space transform to convert the layer and camera positions to world coordinates. This is only necessary if the layer or the camera is the child of another layer, but it makes the expression more general to assume that’s the case. If you don’t have to worry about parenting, you could use something like this instead:

    delta = position – thisComp.activeCamera.positon;

    The next line:

    radiansToDegrees(Math.atan2(delta[0],delta[2]))

    This is pure trig. Looking from the top, the vector calculated in the first line defines the y rotation that you need to get the layer to turn towards the camera. That y rotation can be calculated from the arc tangent of the x and z components of the vector (that’s what atan2() does). JavaScript represents angles in radians, but AE’s rotation property expects degrees, so we use radiansToDegrees() to do the conversion.

    Hope that helps – it’s a lot to bite off if you aren’t comfortable with a little vector math and trig.

    Dan

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