Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Wheel Rotation On/Off Controller

  • Wheel Rotation On/Off Controller

    Posted by Jaan Koppe on August 19, 2014 at 8:38 am

    Hi. I am creating a “2D Car Rig” to easily animate different part of the car.

    Having trouble with the Wheels rotation. I have the wheels rotating when the Car is Moving on the x axis. I want that the rotation stops when a checkbox is enabled.

    It works but the wheels are going to rotation value 0, when the checkbox is enabled.

    My question is that how can I define the last position and stay to it while the chekcbox is enabled and continue on from that point when the checkbox is disabled ?

    Thanks!

    Jaan Koppe

    if (comp("Main").layer("CarControl").effect("Break On")("Checkbox") == 0)
    comp("Main").layer("Truck").transform.position[0]
    else
    0

    Jaan Koppe replied 12 years ago 2 Members · 7 Replies
  • 7 Replies
  • Dan Ebberts

    August 19, 2014 at 10:26 pm

    I think the expression you need is a little more complicated than you might guess. Your expression needs to calculate the cumulative value up to the current frame. That is, it will need to look at the checkbox keyframes in the past and calculate the effect that “on” frames in the past have on wheel’s current value. The details depend on the nature of the your animation, but it can be done.

    Dan

  • Jaan Koppe

    August 20, 2014 at 6:07 am

    Thanks for the Reply Dan!

    For now I have an animation like this:

    https://reels.creativecow.net/film/car-wheel-rotation-test

    Both wheel rotations are driven by the Car’s x value.
    And when the “Brake On” Checkbox is checked, then the First Wheel rotation value is simply 0.

    So i am trying to give the first wheel a constant rotation value which is the current value of rotation. And when the “Brake On” is unchecked, then the Wheel Rotation follow’s the car position x again.

    Jaan

  • Dan Ebberts

    August 20, 2014 at 5:43 pm

    What’s the expression you’re using now?

    Dan

  • Jaan Koppe

    August 21, 2014 at 4:40 am

    This is the first tyre Rotation expression:

    if (comp("Main").layer("CarControl").effect("Break On")("Checkbox") == 0)
    comp("Main").layer("Truck").transform.position[0]
    else
    0

  • Dan Ebberts

    August 21, 2014 at 6:55 am

    I’m surprised that works (as far as matching the tire rotation to the truck’s position). But since it does, you might be looking for something like this:


    cb = comp("Main").layer("CarControl").effect("Break On")("Checkbox");
    if (cb.value == 0){
    comp("Main").layer("Truck").transform.position[0];
    }else{
    t = cb.nearestKey(time).time;
    comp("Main").layer("Truck").transform.position.valueAtTime(t)[0];
    }

    Note that I have not tested this at all, so there are likely some problems with it, but hopefully it will be helpful.

    Dan

  • Dan Ebberts

    August 21, 2014 at 7:15 am

    Sorry–I think I messed that up. It will probably be more like this (but it’s probably still not quite right):


    cb = comp("Main").layer("CarControl").effect("Break On")("Checkbox");
    if (cb.value == 0){
    comp("Main").layer("Truck").transform.position[0];
    }else{
    n = cb.nearestKey(time).index;
    if (time < cb.key(n).time) n--;
    t = cb.key(n).time;
    comp("Main").layer("Truck").transform.position.valueAtTime(t)[0];
    }

    Dan

  • Jaan Koppe

    August 22, 2014 at 7:19 am

    Thanks for the code Dan!

    The breaking part works very good, until the brake will be “released”, then the wheel rotation value goes back to the car’s position value.

    I think, that now I need to track the car’s position to get the current x value and apply that when the checkbox is unchecked?

    I added a few lines to the code, got no error’s but also no result:

    need to use some other approach I think 🙂

    tx = comp("Main").layer("Truck").transform.position;
    n2 = tx.nearestKey(time).index;
    if (time &lt; tx.key(n2).time) n2--;
    t2 = tx.key(n2).time;

    cb = comp("Main").layer("CarControl").effect("Break On")("Checkbox");
    if (cb.value == 0){
    tx.valueAtTime(t2)[0];
    }else{
    n = cb.nearestKey(time).index;
    if (time &lt; cb.key(n).time) n--;
    t = cb.key(n).time;
    comp("Main").layer("Truck").transform.position.valueAtTime(t)[0];
    }

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