Linking position of one layer to a shape layers trim path

Scripting for After Effects

Linking position of one layer to a shape layers trim path

Postby TheoWilliams on 08/13/2015, 4:51 am

Simple map build using a shape layer path as the position data for a car - with the shape layer producing a dotted line following it.

Need a way to control the speed this animations happens using a simple slider controller to sync it with VO

atm im retiming it in a pre comp and theres too many key frames - its slowing me down on what needs to be a fast multi video delivery

Currently playing around with:

ctrl = thisComp.layer("ControlNull");
slider = ctrl.effect("Slider Control")("Slider");
n = Math.max(1,Math.min(slider,numKeys));

Hopefully ill be able to ramp up and down the speed at which the car completes the run

The problem with this expression is that at 2.0 (out of 0.0 - 100. on the slider control) my dashed line jumps from 0 - 100%
and at around 18 on my slider the car finishes - although it does gradually complete the run rather than jumping from 0-100

any help would be really appreciated

Posts: 1
Joined: 08/13/2015, 4:24 am
System Specs: 5k Imac
3.5ghz i5 intel chip

Re: Linking position of one layer to a shape layers trim path

Postby star+circle on 08/24/2015, 5:15 am

I answered this on Creative Cow After Effects Expressions forum with a solution of how to use the 0 to 100 range of the slider to complete the trip. With picture attached. Did you try that method?
Posts: 731
Joined: 12/6/2014, 3:07 pm
Location: Finland

Re: Linking position of one layer to a shape layers trim path

Postby pavelusha on 08/27/2015, 6:05 pm

It's actually very easy and simple to do.

Lets say you drew the shape layer path and then using Trim animated how you draw the line. So there on the "End" attribute you gonna get the percentage from 0 to 100. and you can put as many keyframes there as you need.
Then you copy the path from that line and paste it on to your car layer's position.
Then stretch the position keyframes along the timeline so the first keyframe will be on the first frame and the last on the last frame (when you paste keyframes AE will paste it with "Rove across time" attribute set, so you can just move the first keyframe to the first frame and the last keyframe to the last frame).

Then write this expression on the position:

valueAtTime(thisComp.duration/100*thisComp.layer("Shape Layer 1").content("Trim Paths 1").end);

Your car position will exactly match the end of your line.
So then you can connect "end" attribute with a slider.
Hope my explanation makes sense.
Posts: 4
Joined: 10/31/2010, 3:57 am

Return to After Effects Expressions