Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

New Here ,
Jan 27, 2016 Jan 27, 2016

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 www.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)

TOPICS
Expressions
2.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 27, 2016 Jan 27, 2016

I'm not clear what you are asking. You will not get any "fixed distance" out of Dan's code, either. It's all based on temporal logic if and when an object was at a given position at a given time. It's simply unsuitable for what you seem to be after. The rest we can't know. We know nothing about your project, but presumably nothing in your comp is actually animated in a way that the expressions could actually work.

Mylenium

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jan 27, 2016 Jan 27, 2016

If you use an expression valueAtTime(travel - offset), the followers will stack when the leader stops moving.

You need to give the offset another meaning (completion offset, not time offset).

Here's a set up that works, more or less (there might be something better, looks a bit rigid imo, and i didnt work out the orientation):

1- Copy the motion path to a Null ("Null 1") and make sure that all keyframes are in "roving" state (that's the default when you copy a mask path to a motion path).

2- If you don't want the cars to stack when the leader reaches the boundaries of the motion path, put a loop expression in the position of the null

    if the path is closed:

loopOut("cycle", 1);

    otherwise:

if (time<key(1).time) loopIn("continue") else loopOut("continue");

3- Put a travel and offset slider on the null (i called them "Completion %" and "Completion offset per car (%)");

4- Put an expression on all cars positions (the first is assumed to be named "LEADER")

N = thisComp.layer("Null 1");

pos = N.transform.position;

t = N.effect("Completion %")("Slider").value;

t -= N.effect("Completion offset per car (%)")("Slider").value * (index-thisComp.layer("LEADER").index);

t = (pos.key(pos.numKeys).time - pos.key(1).time) * t/100;

pos.valueAtTime(t);

The value of "Completion offset per car (%)" should be quite small, 1 maybe (depends of your path)

Xavier.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 27, 2016 Jan 27, 2016

Hi Xavier (UQg),

That makes things easier with the car spacing, thanks. When I move the "Completion %" slider the cars move, but how do I make them move on their own when I hit the play button?

I have shown a comparison, the first row of cars is moving using my old expression, the second row of cars don't move when I hit play. test-car-intersection(Xavier-comparison).aep

Please excuse my beginner-ness, I feel like I am missing fairly obvious knowledge here that you may take for granted thinking I already know it. Maybe there is a tutorial out there you can point me too?

Cheers,

Russell

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 13, 2016 Sep 13, 2016
LATEST

Your expression solution worked perfectly for me. I'm been looking all over the internet for a way to have both front and rear wheels of my 2d car move alonga  path while being offseted by a fixed amount (the distance between the wheels).
This works beautifully, and animating the car position via the slider is a LOT easier than animating the motion path keyframes!

If this solutions is not ideal for the original post problem, I can testify that it works perfectly for animating a car, bycicle or anything with multiple wheels moving along a path.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 27, 2016 Jan 27, 2016

In your project file, duplicate the Car layer a couple of times, set the offset slider to 270 and animate the travel slider from 27 to 100. That should get you closer to what you're trying to do (I think).

The travel slider creates all the movement--the cars won't necessarily track the null (they just follow its path, not its timing).

Dan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 27, 2016 Jan 27, 2016

Hi Dan,

Thank you for your reply, I am very happy to actually be able to ask you personally about your expressions on motionscript.com. I am new to After Effects so if you don't mind can you spell out exactly what you mean by the travel slider creates all the movement? How do I get the cars to move without manually moving the travel slider myself?

I filmed an intersection for an hour or 2 and want to make a continuous loop of how the intersection works, moving the cars identical to the real life footage. The following expression would be perfect for me if the cars didn't stack up when the leader car comes to a stop at a red light.

delay = 50; //number of frames to delay

d = delay*thisComp.frameDuration*(index - 1);

thisComp.layer(1).position.valueAtTime(time - d)

The below expression on your website seemed to be what I am looking for, but I just can't get my head around this I have spent the past few hours using your advice 'animate the travel slider from 27 to 100' do you mean manually .

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)

I have compared both methods in the same file test-car-intersection(Dan-Comparison).aep

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 27, 2016 Jan 27, 2016

You would animate the travel slider by keyframing it, or possibly (if it was some kind of periodic or random motion) with an expression.

Dan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 27, 2016 Jan 27, 2016

I think that's what I didn't understand, unfortunately I am unsure of how to keyframe the travel slider. Do you know of any tutorials on keyframing sliders?

Is that how you made your stars move on the article on your website? Creating Trails

Would you maybe still have the original After Effect .aep files you used to make those stars?

Cheers,

Russell

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 27, 2016 Jan 27, 2016

>Do you know of any tutorials on keyframing sliders?

I'm sure the help manual covers it. You just click the property's stop watch to set the first one, move the time indicator to where you want the second keyframe, and set the new value.

>Is that how you made your stars move on the article on your website?


Yes.


>Would you maybe still have the original After Effect .aep files you used to make those stars?

I pretty sure do, but it was created with an ancient version of AE. I think AE CS5.5 is the newest version that will still open the file.

Dan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 27, 2016 Jan 27, 2016

Would you be able to make it available? that would make my day! even if its CS5.5 I am about to start a motion graphics short course at RMIT I am sure a teacher or someone there will have the older versions of AE. I am particularly keen on learning the "Following the Null's Orientation" and it would definitely help if I can see your project file.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 27, 2016 Jan 27, 2016

Sure, just contact me through the link on my site, and I'll shoot it to you.

Dan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 27, 2016 Jan 27, 2016

Okay I figured out how to keyframe the slider. This is what I was missing from the start, as a beginner, it just went over my head. For any other beginners out there you go to the layer with the "null objects name" > Effects > "travel sliders name" > right click on the "travel sliders name" > add keyframe > adjust slider and repeat until you have a bunch of keyframes. Thanks everyone for all your help, much appreciated.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 27, 2016 Jan 27, 2016

Is there a way to loop an animation when using sliders? loopOut() works for the null object but it doesn't work for the cars following the null objects path.

This is the expression I am using for the position on the car.

start = 0; //start time of template motion

end = 300.0; //end time of template motion

t = thisComp.layer("template");

offset = (t.effect("offset")("Slider")/1000)*(index -1);

travel = linear(t.effect("travel")("Slider")/1000,start,end);

t.position.valueAtTime(travel - offset)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines