Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity › Forums › Adobe After Effects Expressions › Movement started by multiple Marker

  • Movement started by multiple Marker

    Posted by Dominique Parisi on February 14, 2020 at 1:55 pm

    Hi !

    I’m trying to set up an animation tool aimed to be used quite regularly.
    I’ve done a lot by myself by trial and error, but being quite a novice about coding, I’m turning to you.

    What the expression is suppose to do is moving, a comp along the Y axis, by 500px, when it hit a marker “Move” and move it depending of the marker.duration.
    The movement value will depend on the composition height ( which changes depending of the project i’m on. So it has to be manually specified.)

    Then, when it hit’s another “Move” marker, the movement continue from the position it reached and add again the + 500px

    marker1 => 0 to 500,
    marker2 => 500 to 1000
    marker 3 => 1000 to 1500 and so on…

    I was thinking using the marker index to multiply the end position.
    what I got from reading on the board is the expression move once, then go back to 0 and redo the movement.

    // move = 500*marker.nearestKey(time).index => what I though might works, but, it’s start from 0 and go to 1500 if it’s 3rd marker.

    Thank you for any help and advice of related post I might have missed 🙂

    ***
    // Set the position of the object
    mainPos = comp("_CONTROL_PANNEL_CTRL").layer("Obj_Position_CTRL").effect("Obj_Position_Start")("Slider");

    // Set the Object Vertical Offset
    offsetPos = comp("_CONTROL_PANNEL_CTRL").layer("Obj_Vertical_Offset_CTRL").effect("Obj1-Vertical-Position_CTLR")("Slider");

    // Object start position by combining mainPos and offestPos
    yPOS = mainPos + offsetPos;

    m = 0;
    t = time;
    Move = 500;

    if (marker.numKeys > 0) {
    m = marker.nearestKey(time).index;
    tag = marker.key(m).comment;
    if (tag == "Move") { t = time - marker.key(m).time }
    linear(t, 0, marker.nearestKey(m).duration, yPOS, Move)
    }

    Dominique Parisi replied 6 years, 6 months ago 2 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    February 14, 2020 at 11:44 pm

    I’m not 100% sure from your description, but I think it will look something like this:


    moveAmt = 500;
    m = marker;
    val = value;
    if (m.numKeys > 0) {
    n = m.nearestKey(time).index;
    if (time < m.key(n).time) n--;
    accum = 0;
    y = 0;
    if (n > 0){
    if ( n > 1){
    for (i = 1; i < n; i++){
    if (m.key(i).comment == "Move") accum += moveAmt
    }
    }
    if (m.key(n).comment == "Move"){
    t = time - m.key(n).time;
    y = linear(t,0,m.key(n).duration,0,moveAmt);
    }
    val = value + y + accum;
    }
    }
    val

    Dan

  • Dan Ebberts

    February 14, 2020 at 11:51 pm

    This is better if you have any Move markers that have zero duration:


    moveAmt = 500;
    m = marker;
    val = value;
    if (m.numKeys > 0) {
    n = m.nearestKey(time).index;
    if (time < m.key(n).time) n--;
    accum = 0;
    y = 0;
    if (n > 0){
    if ( n > 1){
    for (i = 1; i < n; i++){
    if (m.key(i).comment == "Move") accum += moveAmt
    }
    }
    if (m.key(n).comment == "Move"){
    t = time - m.key(n).time;
    y = (m.key(n).duration > 0) ? linear(t,0,m.key(n).duration,0,moveAmt) : moveAmt;
    }
    val = value + y + accum;
    }
    }
    val

    Dan

  • Dominique Parisi

    February 15, 2020 at 9:19 am

    All right !

    Thx, I’ll try this as soon as possible and get back to you !

    All th best !

  • Dominique Parisi

    February 17, 2020 at 7:19 am

    At last, I finally tested it !

    I works like a charm ! Thank you so much for the help, good sir !.

    many thx !

    All the best

  • Dominique Parisi

    April 1, 2020 at 2:31 pm

    Hello There !

    I’m back with half a problem.

    After editing the code you kindly provided. I wanted to do the same thing but by combining the :” Inertial Bounce ” script you wrote.

    It kinda works. except the movement do not go gradually from 0 to 300, but instead it jumps right to it.

    I understand the problem is not having the ” .duration” of the marker being referenced in the expression.

    A weird thing also appeared and I completely not understand why, the first marker is triggering a bounce but… no movement. As it should move from 0 to 300 on the marker duration and so on when hitting the next one.

    Here a gif
    https://ibb.co/5sRSt3F

    Thanks you any help provided.

    moveAmt = 300

    if (m.numKeys > 0) {
    n = m.nearestKey(time).index;
    if (time &lt; m.key(n).time) n--;
    accum = 0;
    y = 0;
    if (n > 0){
    if ( n > 1){
    for (i = 1; i &lt; n; i++){
    if (m.key(i).comment == "Spin") accum += moveAmt
    }
    }
    if (m.key(n).comment == "Spin"){
    t = time - m.key(n).time - 1;
    y = velocityAtTime(m.key(n).time) ;
    amp = .05;
    freq = 4.0;
    decay = 8.0;

    }
    val = y + amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t) + accum;
    }
    val
    }

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