Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Expression to move camera at steady speed with slider control

  • Expression to move camera at steady speed with slider control

    Posted by Gerhard Human on August 7, 2020 at 6:47 am

    Hi all.
    I’m trying to do something rather simple but it’s breaking my head.

    I have a bunch of cameras at different positions in the timeline. They all need to move on the Z axis at a steady constant speed but at some point I need to stop one of the cameras.

    So I’ve been using the script below, placed on each of the cameras.

    It works perfectly but I’ve tried a number of ways to get the camera to stop but I can’t figure out how to determine the last value of the position applied by the script. It keeps going back to the original layer position.

    Is there a way to move the position without using the “time” expression?
    (something like currentPosition += 10 and then you can substitute the 10 with a slider or something like that 😛 )

    var CamSpeed = thisComp.layer("Adjustment Layer 1").effect("Cam_Speed")("Slider");
    var PULL = value[2]-(time*CamSpeed);

    [value[0],value[1],PULL];

    Gerhard Human replied 5 years, 11 months ago 2 Members · 4 Replies
  • 4 Replies
  • Andrei Popa

    August 7, 2020 at 7:13 am

    You could put a marker on the camera layer at the point that you want it to stop and use this expression


    var CamSpeed = thisComp.layer("Adjustment Layer 1").effect("Cam_Speed")("Slider");

    var PULL = time < marker.key(1).time ? value[2] - time * CamSpeed : value[2] - marker.key(1).time * CamSpeed;
    [(value[0], value[1], PULL)];

    Andrei
    My Envato portfolio.

  • Gerhard Human

    August 7, 2020 at 7:21 am

    Thanks Andrei, really appreciate it.

    OK please excuse my incompetence but I’m not getting the marker bit… I added a marker on the main timeline (shift+1, or even manually adding a marker with no name, also named it 1 manually) I also tried adding a marker on the actual camera where the script is situated but I keep getting the error: “expression result must be of dimension 3, not 1”

    Am I missing something?

  • Andrei Popa

    August 7, 2020 at 7:29 am

    It’s my mistake. I am sorry, the autocorrect on my text editor added parenthesis on the last lane for no reason. Here is the actual expression.


    var CamSpeed = thisComp.layer("Adjustment Layer 1").effect("Cam_Speed")("Slider");

    var PULL = time < marker.key(1).time ? value[2] - time * CamSpeed : value[2] - marker.key(1).time * CamSpeed;
    [value[0], value[1], PULL];

    Andrei
    My Envato portfolio.

  • Gerhard Human

    August 7, 2020 at 7:33 am

    You sir are a legend. Thanks so much. Works perfectly ☺

    Really appreciate it

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