Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity › Forums › Adobe After Effects Expressions › motion path cars to follow leader (null object) and maintain a fixed distance

  • motion path cars to follow leader (null object) and maintain a fixed distance

    Posted by Russell Beyer on January 27, 2016 at 11:15 am

    I am trying to create a model of my local intersection where a car will ease to a stop at a red light and the chain of cars behind will follow and stop at a fixed distance behind the car in front.

    I’m so close yet so far to the solution to this, I am still fairly new to expressions so I need a bit of help. I previously made a freeway with about a 1,000 cars by using a CG Snake tutorial by Jerzy Drozda Jr at maltaannon.com, but starting this next project I realized this method did not allow the cars to maintain a fixed distance.

    I then read Dan Ebberts article “Creating Trails” of motionscript.com and found that Jerzy Drozda’s method, while perfect for small projects, is problematic with a large amount of objects because it uses a “cascading” expression, where the expression in one layer refers to the previous layer which refers to the previous layer, etc. This can enormously increase the amount of work that After Effects has to do at each frame. I had first hand experience with this when I made my freeway. After Effects was nearly impossible to use because there was a 10 second lag after every click.

    Which brings me to my current problem, getting this expression to work I have attached the file I am working on as a download link from my Google Drive here

    Here is the original formula from motionscript.com – if you want to see his guide just search “//start time of template motion” in Google and click on this first link.

    I have tried so many things with this expression but the dam car just refuses to follow the null object!

    // in Position property:
    strt = 0; //start time of template motion
    end = 4.0; //end time of template motion

    t = thisComp.layer("template");
    offset = (t.effect("offset")("Slider")/100)*(index -1);
    travel = linear(t.effect("travel")("Slider")/100,strt,end);
    t.position.valueAtTime(travel - offset)

    // in Orientation property:

    strt = 0; //start time of template motion
    end = 4.0; //end time of template motion

    t = thisComp.layer("template");
    offset = (t.effect("offset")("Slider")/100)*(index -1);
    travel = linear(t.effect("travel")("Slider")/100,strt,end);
    if (travel <= offset){
    vect = t.position.velocityAtTime(0);
    }else{
    vect = t.position.velocityAtTime(travel - offset);
    }
    lookAt(position, position + vect)

    Kalleheikki Kannisto replied 10 years, 8 months ago 2 Members · 1 Reply
  • 1 Reply
  • Kalleheikki Kannisto

    January 28, 2016 at 3:31 pm

    You are using the “travel” slider to move the car, so you have to animate that slider value from 0 to 100.

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