Copy link to clipboard
Copied
I would like to rotate something back and forth, every 4 seconds. How do I add the 4 sec variable to a loop expression? I assume AE can do this, I'd prefer not to keyframe it. Thanks.
Copy link to clipboard
Copied
The easiest thing to do is set one keyframe for rotation at 0 seconds then a second keyframe at 4 seconds. If you want the rotation to go back and forth then add this expression:
loopOut("pingpong")
If you want the rotation to loop then use this expression:
loopOut()
If you want the loop to be seamless then the first and last keyframe must put the layer in exactly the same position.
Copy link to clipboard
Copied
Thanks. So I want to rotate to the left, pause 4 seconds and rotate back to the right (starting position), pause 4 seconds. I thought maybe there was a way to do it using a loop expression with a pause.
Copy link to clipboard
Copied
I think you don't get Rick answer, please take a look on this link so you can understand better how to use loopOut("pingpong")
https://www.schoolofmotion.com/blog/loop-expression-after-effects
Copy link to clipboard
Copied
You can use something like this to do it without keyframes. This only does the first 4 seconds but you can adapt it. Plus you can add expression controllers to control the speed.
if (time<4) time*50;
else
time*-50
Copy link to clipboard
Copied
Alternatively you could really simplify it by using a Cosine wave to control rotation, something like;
Math.cos(time*.75)*100
The multiplier number outside the parentheses controls the amount of rotation. the multiplier number inside the parentheses controls the timing.
Copy link to clipboard
Copied
Here's another with a pause between 4 seconds and 8 seconds;
if (time<4) time*50;
else
if (time>8 & time<12) time*-50
BTW There is a dedicated After Effects Expressions forum which would be a better place for this as it is manned by the wonderful Dan 🙂
Copy link to clipboard
Copied
Thanks. pingpong didn't do it for me. The tutorial was good but didn't provide an obvious solution. I will now try Angie's suggestions, will have to get my math on...
Copy link to clipboard
Copied
what's the issue with: 2x keyframes + loopOut("pingpong") ?
What's not working for you?
Copy link to clipboard
Copied
Sorry for the quality. The crab on the left was my goal, here accomplished using a series of keyframes. The crab on the right is the pingpong method, key frames at 0 and 2 sec. I didn't see how to get it to pause.
Copy link to clipboard
Copied
Without any keyframes, it might look something like this:
period = 2;
rotationDur = 0.25;
rotationAmt = 30;
t = time%period;
if (t < period/2){
ease(t,0,rotationDur,rotationAmt,0);
}else{
ease(t,period/2,period/2 + rotationDur,0,rotationAmt);
}
Dan
Copy link to clipboard
Copied
You ARE the man Dan. I was wondering if there was a better way than my suggestions. One thing I can’t understand is why the rotation duration is .25 and not .75? Am I missing something obvious?
thanks Dan - King of Expressions
Copy link to clipboard
Copied
Hi Angie,
>Am I missing something obvious?
Probably not. It was just a rough guess based on the little movie. It looked like the rotation took about 1/4 of the time and the pause the other 3/4.
Dan
Copy link to clipboard
Copied
I’d recommend using Dan’s expression as you I’d you preferred not to use key frames but if you do decide to go down the key frame route, to create the pause, create your first two KFs for the rotation, then add another KF to create a 2 second pause ( toggle hold the 1st). Then add a pinpong loop to this.
Copy link to clipboard
Copied
ProTip: Any time you have an expression question, google it with 'Ebberts' attached to it. Dan Ebberts is the man with expressions. His answers are always the right ones. And he has a site (motionscript.com) that is super helpful.
Copy link to clipboard
Copied
Ah, OK, I wondered if there was some “magic” for working that out. Thanks Dan 🙂
Copy link to clipboard
Copied
Even if the expression-solution is a great way, this can be done with a simple loopOut(“pingpong”); - Loop as suggested in the first place.
The trick to "hold" the loop is to add another - 3rd - keyframe with the last rotation value on it. To adjust the pause, you just drag the last keyframe around.
Cheers,
Martin
Copy link to clipboard
Copied
Interesting answers and dialogue. Thanks...