FORUMS: list search recent posts

Animating a slider control with a checkbox

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
adam fuller
Animating a slider control with a checkbox
on Feb 26, 2014 at 10:21:27 pm

I'm working on a project right now where I'm using a set of sliders to control various puppet pin positions. When you animate a slider the puppet takes a shape, a different slider a new shape.

What I need it to do now is automatically animate the slider from 0-100 over an arbitrary amount of time (I'm testing right now with 2 seconds) whenever a checkbox is keyframed On, and animate 100-0 when it's checked off.

So far I've been able to get the slider to animate 0-100 using the added expression, I'm using linear() to change the values, and am defining the in and out points via nearestKey(time).time and nearestKey(time).time+2

This works like expected, but as we approach an off keyframe for the checkbox, the value suddenly jumps from 100-1 in a single frame, well before we are even close to the next keyframe.

Any help is appreciated,

Adam

if (effect("Checkbox Control")("Checkbox") >0) {
linear(time,effect("Checkbox Control")("Checkbox").nearestKey(time).time,effect("Checkbox Control")("Checkbox").nearestKey(time).time+2,0,100);
}else{
value
}


Return to posts index

Dan Ebberts
Re: Animating a slider control with a checkbox
on Feb 27, 2014 at 2:11:33 am

It will probably be something like this:


cb = effect("Checkbox Control")("Checkbox");
n = 0;
if (cb.numKeys > 0){
n = cb.nearestKey(time).index;
if (cb.key(n).time > time) n--;
}
if (n > 0){
t = time - cb.key(n).time;
if (cb.key(n).value)
linear(t,0,2,0,100)
else
linear(t,0,2,100,0);
}else
value



Dan



Return to posts index

adam fuller
Re: Animating a slider control with a checkbox
on Feb 27, 2014 at 4:51:19 pm

Thanks Dan, that worked for the checkbox, I actually found something similar last night that you posted to another thread about scaling with a checkbox.

Basically what I'm trying to set up is "Blendshapes" like you would see in a 3d program like maya. I have a mouth puppet rig set up and am trying to make it simple for lip sync later on.

As I kept building the rig I realized I needed to have multiple sliders to trigger at different times, from one set of keyframes. So I've changed the checkbox control for a different slider that's using hold keyframes, I've posted the modified script below.

So on keyframe.value 10, the first slider fires and moves from 0-100, but all the other sliders do their 100-0 animation. Any keyframe that isn't the correct trigger for that slider makes it do it's second animation.

So now I'm trying to find a way to only have them animate 100-0, if they were either already at 100, or if the previous keyframe was their trigger.

Any ideas?

sc = effect("123")("Slider");
sTime = 1;
sStart = 0;
sEnd = 100;
v=0;

if (sc.numKeys > 0){
n = sc.nearestKey(time).index;
if (sc.key(n).time > time) {
n--;
}
if (n > 0){
t = time -sc.key(n).time;
if (sc.value==10){
v = linear(t,0,sTime,sStart,sEnd);
}else{
//if(oldv==10){
v = linear(t,0,sTime,sEnd,sStart);
//}

}
v;
}else{
value;
}
}else{
value;
}


Return to posts index


adam fuller
Re: Animating a slider control with a checkbox
on Feb 27, 2014 at 8:01:47 pm

Actually I seem to have got it working now, it's not ideal but I think it'll do for the project I am working on.

Now when it looks at the value of the nearest keyframe, and it's equal to the value it wants (in this case 10) it starts the 0-100 animation. When the nearest keyframe changes to something else, it looks at the previous keyframe to see whether it was the value it wanted (10) before firing the 100-0 animation.

This keeps all the expressions from firing the 100-0 animation before they are at 100.

There are still some issues, you need 2 keyframes at the start of the animation, I used frame -1 and -2, or else the the expression will attempt to evaluate a keyframe[0] and receive an error.

Also, if you try have 2 keyframes that are the same in a row, the second one restarts the animation back to 0-100 even though the value was already 100.

For this puppet rig I'm working on I don't think it will cause any problems, but if anyone knows an easy solution for these problems I'm all ears.

sc = effect("123")("Slider");
sTime =.1;
sStart = 0;
sEnd = 100;
v=0;
oldv=0;
if (sc.numKeys > 0){
n = sc.nearestKey(time).index;
oldv=n;
if (sc.key(n).time > time) {
n--;
}
if (n > 0){
t = time -sc.key(n).time;
if (sc.value==10){
v = linear(t,0,sTime,sStart,sEnd);
}else{
if(sc.key(sc.nearestKey(time).index-1)==10){
v = linear(t,0,sTime,sEnd,sStart);
}

}
v;
}else{
value;
}
}else{
value;
}


Return to posts index

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