ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Layer follows Stroke start

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Aaron Pozzer
Layer follows Stroke start
on Apr 17, 2011 at 12:36:12 pm

hey all. first post here. i've been searching for an answer for this problem for about a week. im starting to think an expression is the only way to solve it, and even then, im not sure...

here is the issue:

i am animating a map. i have a traveling line setup as a path with a Stroke effect applied. the 'start' has been animated to have the path travel over time. nothing new here.

i also want a layer to sit ontop of the head of the Stroke as it travels (a graphic, say a ball/circle, so its not just a line traveling over a map).

in searching for how to get a layer to follow a paths position, i found that apparently the only way to do this is to paste the path into the layers position channel. so i did this and it works.

so lets say i set the start key for both the stroke and the layer at 1, and the end key at 100. they both move along the shape of the path together. no problem.

the problem is i dont want a linear animation. i have not been able to figure out a way to make a change to the animation of 1 and have the other do the same thing, so they are always on the same position on the map. the stroke is animating off a % of the 'start' property, and the layer is following a path with 2 keyframes and all those 'rove across time' black circles in-between.

i though, perhaps there is an expression that could say "When the layer is here (the starting point) this is 0%, and when the layer is here (the ending point), this is 100%", and then that would be a value that the Stroke start would understand. this way, at least in my head, i would think that i could make changes to the animation of the layer by adding keys to the roving keys, and sliding them around so i get some animation happening, and then theoretically the Stroke would follow since animating the layer position is now effectively animating the Stroke start value.

though, im not entirely sure this would work, as the path is NOT a straight line, and i dont know that position to percent translation would work. i dunno... im just thinking out loud here.

so yes, this is the problem! im open to ANY solution at this point, even if it means a completely new way of setting this up.

my current fallback plan is to use a 'write-on' effect instead of a stroke as that has a 'brush position' property which i could probably set to follow the path, and pickup any timing changes i make to it, though i havent tried this yet.

2nd fallback plan is to precomp it and and time remap it, though i realy dont want to have to do that, as the layer is actually already a looping graphic precomp, and if i time remap THAT, the animation will get all weird.

surely someone must have done this before as it seems a very common thing to have to do. inquiries on other forums have not yielded any results, so im hoping the bright minds here can shed some light.

thanks all! (sorry for the overly wordy description)


Return to posts index

Dan Ebberts
Re: Layer follows Stroke start
on Apr 17, 2011 at 5:55:13 pm

You could let the percent completion of the stroke animation drive the graphic layer's position. Just past the stroke path into the graphic's position property, and add a Position expression like this:

percent = thisComp.layer("map layer").effect("Stroke")("End");
valueAtTime(percent*key(numKeys).time/100)

Don't alter the position keyframes and the graphic should follow the stroke perfectly.

Dan



Return to posts index

Aaron Pozzer
Re: Layer follows Stroke start
on Apr 18, 2011 at 12:06:14 am

hmm, interesting. thanks dan. i will try this in the morning and let you know how it goes!


Return to posts index


Aaron Pozzer
Re: Layer follows Stroke start
on Apr 18, 2011 at 1:06:38 pm

hey Dan. so, this works, but not quite off the bat, though i figured it out.

i have the Stroke start set to start animating at frame 25. the 1st key in the graphic layer position was also set at 25, so they would start together.

so i left the position keys alone, pasted in your expression, added a tweak via some additional keys in the Stroke start, and it did follow, but it was delayed by 23 frames.

on a hunch i set the 1st position key for the graphic back to frame 0, and now everything follows properly.

it would be great if you could explain to me how this expression works, in plain english. im tryin to learn expressions, and i've only been at it for a couple weeks. id love to be able to understand the logic of how it does what its doing.

thanks alot!


Return to posts index

Dan Ebberts
Re: Layer follows Stroke start
on Apr 18, 2011 at 4:18:28 pm

When you paste a path into a position property, you get a smooth animation that lasts two seconds. Sorry, I forgot to mention that you needed to make sure you pasted it in at time zero. Since the Start and End properties of the Stroke effect represent percent travel along the same path, all the expression does is convert that percentage to an equivalent time between zero and two and then use valueAtTime() to extract the corresponding position from the Position property version of the path.

Dan



Return to posts index

Aaron Pozzer
Re: Layer follows Stroke start
on Apr 18, 2011 at 4:56:47 pm

ok, so let me see if i understand this...

-valueAtTime, means: be this value (that we are about to calculate inside the brackets) right now?
-percent, well thats obvious.
-*key(numKeys), the number of keyframes, in this case 2.
-.time/100, the current time (frame #?) divided by 100?

this last part is what confuses me. is it numKeys x frame# / 100?

so, the path gets converted into 2 keyframes and into a linear animation, 0% at key1 and 100% at key2 (hence the /100 at the end?). every point on the path in between is just an interpolation so the graphic sticks to the path and maintains that constant linear speed. the shape of the path is not important, only that its getting from point A to B over a linear number of frames...?

so if it was frame 75, and the stroke was at 18%, it would be valueAtTime = (18x((2x75)/100))? so it would return a value of 27? meaning the graphic should be 27% way through its animation?


...am i on the right track here? :)


Return to posts index


Dan Ebberts
Re: Layer follows Stroke start
on Apr 18, 2011 at 5:47:46 pm

valueAtTime() means get the value of this property (position) from the time (in seconds) calculated inside the parenthesis.

key(numKeys).time is the time of the last position keyframe. Normally there would be more than two. If your stroke path has curves in it, you should get some roving keyframes between the two linear ones on each end. In any case, this gives you the time of the last one (which should always be two seconds in this case). So I guess you could replace:

valueAtTime(percent*key(numKeys).time/100)

with this:

valueAtTime(percent*2/100)

Using your example, if the stroke was at 18%, the position expression should extract the value from 18*2/100 or .36 seconds. So 18% stroke corresponds to 18% travel.

Dan



Return to posts index

Aaron Pozzer
Re: Layer follows Stroke start
on Apr 18, 2011 at 7:07:48 pm

damn, confusing. its worse that time is in seconds, not in frames! oh well.

i do have lots of roving frames in my position channel between the 2 keys. it seems that no matter how long you stretch the 2nd key out to, the expression still works. were you aware of this? cause it seems like your math was based on the fact that you assumed the keys were spaced 2 seconds apart. either way it seems to work... so just fyi.

i got that book, After Effects Expressions, and im making my way through that. hopefully once im done this will make more sense.

thanks alot for you're help Dan! im sure ill have more questions soon enough.


Return to posts index

Dan Ebberts
Re: Layer follows Stroke start
on Apr 18, 2011 at 9:33:22 pm

The version that uses key(numKeys) should work even if you stretch the keyframes out (why would you though?). It won't work if the first keyframe isn't at time zero though (although it would be easy to modify the code to allow for that (not tested, but it should be close):

percent = thisComp.layer("map layer").effect("Stroke")("End");
t = linear(percent,0,100,key(1).time,key(numKeys).time)
valueAtTime(t)


Dan



Return to posts index


Aaron Pozzer
Re: Layer follows Stroke start
on Apr 18, 2011 at 9:35:17 pm

well it had been stretched out because when i was setting up the comp originally and i just had the linear motion, the animation still had to span the length of the comp, so i had stretched the keys out to match the keys of the stroke animation.

but, i understand now that it can be left at 2 seconds.


Return to posts index

Aaron Pozzer
Re: Layer follows Stroke start
on Apr 20, 2011 at 1:01:19 pm

hey Dan, just a bit of a curiosity. i was playing around with my map animation (the camera move) and decided to put some rotation on it so it was not just looking straight down at the map. it seems that when this happens, the graphic layer no longer follows the stroke... it jumps off into the lead and seems to get further and further ahead the longer it travels.

if im limited to looking straight down, thats fine, i just thought id ask why this is happening, and is there a way to correct it. if not, not a big deal.

thanks!


Return to posts index

Dan Ebberts
Re: Layer follows Stroke start
on Apr 20, 2011 at 6:40:02 pm

When you paste the path into the position property, you get motion in the xy plane only, correct? Are your map and graphic both 3D layers, and are they separated in z space?

Dan



Return to posts index


Aaron Pozzer
Re: Layer follows Stroke start
on Apr 21, 2011 at 12:05:04 pm

that was actualy my first thought as well, but they are on the same z plane. both sitting right at 0, and neither are parented.

regardless, i talked with the client yesterday and we are NOT going to use the graphic afterall, just the line.... isnt that always the case!?

though, if you DO think of some reason they might have become misaligned after rotating the camera, it would still be good to know.

thanks!


Return to posts index

Aaron Pozzer
Re: Layer follows Stroke start
on Aug 24, 2011 at 11:16:00 pm

so, many months later the misaligned travelling dot comes back to haunt me!

turns out the client now wants the dot back. so to recap the above conversation your suggestions worked great, but when i rotate the camera, the dot no longer follows the line. there is no parenting or different in z space, so im wondering what is causing this.

any ideas?


Return to posts index

Warren Willmott
Re: Layer follows Stroke start
on Sep 9, 2014 at 3:14:05 pm

Dan you sir are a a legend been struggling with this for 2 days, thanks bud

percent = thisComp.layer("line").effect("Stroke")("End");
valueAtTime(percent*key(numKeys).time/100)


Return to posts index


Scott Arledge
Re: Layer follows Stroke start
on Aug 16, 2017 at 7:15:08 pm

Thank you Dan. Works perfectly!


Return to posts index

Darby Edelen
Re: Layer follows Stroke start
on Sep 1, 2011 at 10:38:36 pm

Instead of using 'Stroke' you should consider using the Generate > Write-on effect. You can paste the mask path property from your current stroke into the brush position property of the Write-on effect.

Then you have a layer position to work with in expressions. You can simply link your head point layer's position to the write-on effect's brush position.

Darby Edelen


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]