Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Parented layer spaces – expression formulas for an offset piston

  • Parented layer spaces – expression formulas for an offset piston

    Posted by George Umanov on April 14, 2018 at 4:02 am

    Hi all,

    I’ve been attempting to animate a piston attached to a “wheel”.
    The odd thing about my setup is that the piston is not centered in-line with the wheel – rather it’s offset by a distance from the wheels center.

    I found a great resource on this website on a piston animation setup, where the piston is centered.
    See here:
    https://library.creativecow.net/articles/ebberts_dan/expressions.php

    I was able to duplicate this in After Effects without issues.
    But my several days worth of attempts at animating an offset piston setup have failed.

    Here is my attempt at the math:
    https://i.imgur.com/OHsY3RF.png
    Similar to the above website, just adjusted for the offset.

    I’m pretty sure I keep failing because I have a terrible understanding of layer spaces for “child” layers.

    According to my math, I need the length of “h” – but I don’t know how to write the after effects formula for “h”.
    It’s the piston offset distance on the y-axis. And since my piston if the child of the crank rod, which is the child of the wheel, my attempts don’t work correctly.

    Any help with how to write the expression for “h” will be greatly appreciated.

    Crank rotation:

    rad2deg=180/Math.PI;
    deg2rad=Math.PI/180;
    r=length(this_comp.layer("wheel").anchor_point,position);
    l=length(anchor_point,this_comp.layer("piston").position);
    pistonoffset=sub(this_comp.layer("wheel").anchor_point,this_comp.layer("piston").anchor_point);
    h=pistonoffset[1];
    adjust=Math.asin((r*Math.sin(this_comp.layer("wheel").rotation*deg2rad)-h)/l)*rad2deg;
    -this_comp.layer("wheel").rotation+adjust;

    Piston rotation:

    -1*(this_comp.layer("wheel").rotation+this_comp.layer("crank").rotation)

    View post on imgur.com

    George Umanov replied 8 years, 2 months ago 3 Members · 5 Replies
  • 5 Replies
  • Kalleheikki Kannisto

    April 14, 2018 at 7:43 am

    Why do you need a formula for h if h is a constant?

    Kalleheikki Kannisto
    Senior Graphic Designer

  • George Umanov

    April 14, 2018 at 2:38 pm

    I just figured it would be more accurate to calculate it rather than try to figure out the pixel distance myself, but I suppose I could just throw in a null at the anchors and subtract the y-values myself. I’ll see where that gets me.

    Does each piece need to be in a specific position when I apply the parenting and the expressions? I’m assuming everything need to be position to a “starting point”?

    So wheel at 0 deg, anchor center. Crank rod at specific angle toward the piston, anchored on outside of wheel. And piston at its offset position with 0 displacement, anchored where it meets the crank rod.
    This is where I would apply the parenting, followed by the expressions?

    All my attempts result in a ridiculous “wobble” of the piston, caused by a crank rod end that draws a circle not a line.

  • Steve Bentley

    April 14, 2018 at 3:22 pm

    If the piston and wheel are graphics in the comp you can simplify the whole thing by just parenting one object to the other (with an offset anchor point) and having the animation of one drive the other. Depending on your set up you may have to do an expression that uses only one of the pistons position’s attributes (x or y) so that the rotational motion of the wheel doesn’t make the piston angle.

    You could also use an IK chain. You can do a simple script to make this (hint the child is always “looking” back at the parent) or you could use a free resource like DUIK to set that up for you.

  • Kalleheikki Kannisto

    April 15, 2018 at 7:25 am

    If you use parented nulls, like Steve suggests, the only thing you need to calculate is the x position of the piston connection point, which can be derived with the pythagorean triangle from the distance to the point that is tracing a circle (c).

    The main issue is that parented nulls live in their own coordinate system. The global position of a parented null, courtesy of Dan Ebberts, is:

    L = thisComp.layer(“Null 1”);
    L.toWorld(L.anchorPoint)

    Kalleheikki Kannisto
    Senior Graphic Designer

  • George Umanov

    May 6, 2018 at 6:57 am

    So it turns out the expression was good, but my process of parenting and adding expressions was incorrect. Everything had to be in the “starting position” before any parenting or expressions being added.

    For example: I had to place all parts on a straight line initially, as if the piston and crank rod were all in-line with the center of the wheel. The expression itself handled the offset of the piston. So once the expression was applied, the piston moved to its correct offset position and animated correctly.

    Thanks for all the responses 🙂

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