Hi all - I need to animate a piston for an engine animation I'm working on and I'm having a hard time getting it working properly... my AE expressions skills are basic and I've forgotten trig altogether.
The only sources I've found on this are Dan Ebberts article here on CC from WAY back in 2001, but all the images and links are dead, so it's hard to follow along. I also found this video which seemed promising, other than the fact that it's in Korean...
I was able to mostly follow it, but my attempt isn't working. I think it *might* be that in his example, the piston is oriented on the x axis, and in my engine, the piston is oriented on the y axis, but I don't know how to change the expression to accommodation that. Maybe one of CC's expression wizards can shed some light on that. The code for the Rotation property on the connecting rod is as below.
p.s. is there any way at all to check the values of x, y, and v in the expression above? I tried to write them out to sourceText of a text layer, but that doesn't work.
c = thisComp.layer("Piston");
tLayer = c.toWorld(c.anchorPoint);
cLayer = thisLayer.toWorld(thisLayer.anchorPoint);
x = tLayer - cLayer;
y = tLayer - cLayer;
v = Math.atan2(y,x);
radiansToDegrees(v) + 90;