3 Replies Latest reply on Jan 18, 2012 4:11 AM by Rick Gerard

# Combine Expression and Keyframes

Hello guys.. I hope you all are not bored with me for asking questions

Okay, I got problem (again) here.

I want to make a gear rotating in certain time.

I have googling and I found an expression to solve it.

It gave me this expression..

timeToStart = 2;

if (time > timeToStart){

wiggle(3,25);

}else{

value;

}

and I try to make that.

and what I've got here isssssssssssss.. look at the picture below..

I make my gear start rotating at 6;14 seconds. Look at the Z rotation value and its value is at 0x and 0 degree. Look at the current time. It shows 0;00;05;29

When I moved it to my selection time, look at the picture below..

Look at the current time! It shows 0;00;06;00 and my gear starts to rotating!

and look at the rotation values. It suddenly to be 1x and 240.6 degrees!

All I want is just the gear starts rotating at time as I want and it will start from 0x and 1 degree.. Not suddenly to be 1x and 240.6.. So the gear starts rotating with smooth movement..

• ###### 1. Re: Combine Expression and Keyframes

In the future it would be best to post expression questions on the AE Expressions forum. I'll give this one a shot here anyway...

The problem is that you're defining your rotation by time and you haven't subtracted the start time from the current time. It also looks like you want to start the rotation at 6 seconds and 14 frames. You can't put timecode in as time that way. Time is a decimal value. Assuming 29.97 fps 6;14 = 6.4

Try this:

```timeToStart = 6.47;
if (time > timeToStart){
(time-timeToStart)*100;
}else{
value;
}
```

The only other problem with your expression is that the rotation speed doesn't ramp up smoothly. You can fix this by increasing the complexity of the expression or by rewriting the expression using an expression slider to control the rpm. If you do that then you can simply set keyframes for the slider and ramp up the speed or change the speed over time with ease. You'll get a better solution. Add an Expression slider to your rotating layer, rename it to "rpm" and try this expression.

```slider = effect("rpm")("Slider");//Expression Slider on this layer.
sv = 0;//start value
fNum = timeToFrames(inPoint);
while (fNum < timeToFrames()){
sv += slider.valueAtTime(framesToTime(fNum));
fNum++;
}
sv*thisComp.frameDuration*60
```

I think I got this solution from Dan Ebberts a few years ago. When you get something like this that you might want to reuse turn it into an Animation Preset by selecting all properties of the layer and choosing Animation>Save Animation Preset. It took me a moment to remember what I'd named it.

• ###### 2. Re: Combine Expression and Keyframes

I think this forum may include about expressions..

Wow!!

Thanks a lot!

That was awesome do your expression..

Thank you thank you thank you...

• ###### 3. Re: Combine Expression and Keyframes

Try out the bottom expression. I was updating the answer while you were posting. Let me know if you have any trouble saving animation presets. All you have to do is select all properties you want to animate in the timeline and then save the preset. I keep mine in a special folder that I can copy, put on a stick drive, and haul around with me.

The AE expressions forum is found HERE.