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)