ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Trigger In and Out animation with comps markers

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Dario De Angelis
Trigger In and Out animation with comps markers
on May 26, 2020 at 4:57:22 pm
Last Edited By Dario De Angelis on May 26, 2020 at 5:01:34 pm

Hi guys, I've searched all the forum to my answer but I didn't find it.

I'm working on an interface animation, and I need to find a way to trigger an animation (there two simply ease keyframe) of an UI's elements.
When the cursor passes on it expands, when the cursor leaves it collapse.

I've set two keyframes (some layers have scale, some position) at the start of my layers and used this expression to trigger the animation's keyframes from the first to the second.
n = thisComp.marker.nearestKey(time).index;
if (time < thisComp.marker.key(n).time){
n = n-1;
}
if(n==0){
n = 1
}
t = time - thisComp.marker.key(n).time;
thisProperty.valueAtTime(t)


So the struggle now is to return from the second keyframe to the first. There is a way to do it with expressions?


Return to posts index

Dan Ebberts
Re: Trigger In and Out animation with comps markers
on May 26, 2020 at 6:45:12 pm

I'm not sure if this is what you're after, but give it a try:


m = thisComp.marker;
t = 0;
if (numKeys > 1 && m.numKeys > 0){
d = key(2).time - key(1).time;
tm = m.nearestKey(time).time;
if (time < tm){
t = linear(time,tm-d,tm,key(1).time,key(2).time)
}else{
t = linear(time,tm,tm+d,key(2).time,key(1).time)
}
}
valueAtTime(t)



Dan



Return to posts index

Dan Ebberts
Re: Trigger In and Out animation with comps markers
on May 26, 2020 at 7:51:28 pm

If you want the whole animation triggered at each marker (rather than centered at each marker), it would be more like this:


m = thisComp.marker;
t = 0;
if (numKeys > 1 && m.numKeys > 0){
d = key(2).time - key(1).time;
n = m.nearestKey(time).index;
if (time < m.key(n).time) n--;
if (n > 0){
tm = time - m.key(n).time;
if (tm < d){
t = linear(tm,0,d,key(1).time,key(2).time);
}else{
t = linear(tm,d,d*d,key(2).time,key(1).time);
}

}
}
valueAtTime(t)



Dan



Return to posts index


Dario De Angelis
Re: Trigger In and Out animation with comps markers
on May 27, 2020 at 11:05:12 am

Thanks Dan.

The first expression you posted do (more or less) what I want.
The issue is that the In and Out are consequential:
time hit the first marker and animation goes from KFrame1---K2---K1, then hit the second marker and again, from K1---K2---K1.

What I would like is:
time hit the first marker: animation goes from K1---K2 then stay to K2 position/scale/rotation value until time hit the second marker, then the animation goes to K2---K1.

(Sorry for my bad english, it's not my native language)


Return to posts index

Dario De Angelis
Re: Trigger In and Out animation with comps markers
on May 27, 2020 at 11:46:45 am

Sorry, my bad.

The first expression doesn't do that:

"time hit the first marker and animation goes from KFrame1---K2---K1, then hit the second marker and again, from K1---K2---K1."

but

animation is 10f long, so, time goes 10f before the marker, animation start from K1, then when hit the marker animation is on K2 value and then 10f later on the K1.
So it's pretty like:
00------10(M)----20
K1------K2---------K1


Return to posts index

Dan Ebberts
Re: Trigger In and Out animation with comps markers
on May 27, 2020 at 3:18:08 pm

Something like this should work as long as the markers are farther apart than the keyframes:


m = thisComp.marker;
t = 0;
if (numKeys > 1 && m.numKeys > 0){
n = m.nearestKey(time).index;
if (time < m.key(n).time) n--;
if (n == 1)
t = key(1).time + time - m.key(1).time
else if (n == 2)
t = key(2).time - (time - m.key(2).time);
}
valueAtTime(t)




Return to posts index


Dario De Angelis
Re: Trigger In and Out animation with comps markers
on May 27, 2020 at 3:24:27 pm

You're the greatest of all time.
Works like a charm.

BIG THANKS!


Return to posts index

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