Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Undertanding property speed

  • Undertanding property speed

    Posted by Miguel De mendoza on September 19, 2016 at 1:41 pm

    HI, I’m working on gear system simulation. I have some comps that are gears with diferent teeth number.
    Each gear rotation is driven by a driver gear rotation speed. I have a master gear that rotates at constant speed, and in the other gears I have this expression:

    driver = effect("Driver")("Layer");
    nSplit =driver .name.split("_");
    driverTeeth = nSplit[nSplit.length -1];
    nSplit = name.split("_");
    selfTeeth = nSplit[nSplit.length -1];
    dSpeed = driver .transform.rotation.speed;
    transmision = driverTeeth/selfTeeth;
    dir = (driver.effect("Reversed")("Checkbox").value)? -1 : 1;
    time * transmision *dSpeed * dir + value

    Here is a screenshot of the layers:

    Each gear is driven by the below gear layer.
    With the 2 and 3 gears, it works fine, but the gear 3 speed is returning extreme changing values like -1087, 56, 523… so the gear 4 makes very fast wiggly rotations. Someone can figure out wy is this happening?

    Miguel De mendoza replied 9 years, 7 months ago 2 Members · 7 Replies
  • 7 Replies
  • Xavier Gomez

    September 19, 2016 at 3:40 pm

    Hi Miguel,
    i tried and observed the same starting from third child.
    It seems that AE needs some guiding otherwise it gets lost.
    This expression seems to work fine:

    curLayer = thisLayer;
    multiplier = 1;
    n=0;
    do{
    try {
    driver = curLayer.effect("Driver")("Layer");
    multiplier *= - driver.name.split("_")[1]/curLayer.name.split("_")[1];
    curLayer = driver;
    ++n;
    }
    catch(e){driver = null;};
    }while(driver!=null);
    if (n===0) value else {
    leadRot = curLayer.rotation;
    thisLayer.rotation.valueAtTime(inPoint)-leadRot.valueAtTime(inPoint) + multiplier* (leadRot.value-leadRot.valueAtTime(inPoint));
    };

    Xavier

    Xavier

  • Xavier Gomez

    September 19, 2016 at 3:44 pm

    Hum, just realized that the expression works because i didnt put a Layer Control on the leading gear.
    If you put one, you’ll get an infinite loop and a time out error.
    It would be better to change the break condition to :

    while(driver!=null && driver.name!==curLayer.name)

  • Miguel De mendoza

    September 19, 2016 at 5:03 pm

    Thanks Xavier, it works perfect! Yes, it seems some stacking expression problem.

  • Miguel De mendoza

    September 19, 2016 at 5:35 pm

    I Works for me like the first example. But I found another problema for the setup. I’m controling the speed of the lead gear with this expression:

    thisComp.layer("Controls").effect("Master_Speed")("Slider") * time

    Because I’m triggering the speed of the driver when I increase the speed of the Master_Speed with keyframes, the gears go so fast. So I need to implement an acceleration formula to the expression. I have the formula for acceleration:

    deltaTime = 1/25;
    iv = thisComp.layer("gear_5").transform.rotation.speedAtTime(time - deltaTime ); //Initial velocity
    fv = thisComp.layer("gear_5").transform.rotation.speed; //Final velocity
    (iv - fv)/dT

    But I don’t know how to implement it on the expression. Any Idea?

  • Miguel De mendoza

    September 20, 2016 at 9:15 am

    Finally I found a simplest way to make all the teeth fint on the gears while moving. Simply I multiply the transmisión by the position of the driver:

    driver = effect("Driver")("Layer");
    nSplit =driver .name.split("_");
    driverTeeth = nSplit[nSplit.length -1];
    nSplit = name.split("_");
    selfTeeth = nSplit[nSplit.length -1];
    dSpeed = driver .transform.rotation;//.speed;
    transmision = driverTeeth/selfTeeth;
    dir = (driver.effect("Reversed")("Checkbox").value)? -1 : 1;
    transmision *dSpeed * dir + value

    It works for all the gears. I still have the problem with the acceleration. My Master gear rotation is driven by the expression :

    thisComp.layer("Controls").effect("Master_Speed")("Slider") * time

    But when I add keyframes to the slider to increase the speed, the gear start to rotate very fast till the interpolation ends. Is posible to get an incremental amount of the speed with keyframes on the slider?

  • Xavier Gomez

    September 21, 2016 at 6:43 am

    If the leading gear is driven by a speed slider, you should use for that gear an expression as explained in Dan’s website https://motionscript.com/articles/speed-control.html

    For all other gears, i think that the expression i posted will work.

    For these gears, you dont need a “inverse” checkbox, since a gear necesserily rotates the way opposite to its “parent”.
    And the expression for these gears should not mention a “speed” variable either, otherwise you’ll need to integrate that speed, which can be super slow, and not necessary. (Overall, the rotation variation is a multiple of the rotation variation of the leader rotation, and that multiple is only determined by size ratios).

    Xavier

  • Miguel De mendoza

    September 21, 2016 at 10:04 am

    Thanks Xavier, that was one of those posts that I read time ago and I forget XD. Pretty usefull!

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