Activity › Forums › Adobe After Effects Expressions › expression to rotate foward
-
expression to rotate foward
Posted by Criis Daw on May 24, 2010 at 10:17 amHi,
I might be cheating and getting someone else to do my homework for me, but have you ever tried to work out expressions with a baby on your lap ?Any way i would like to have a expression that that rotates a null object by so many degrees at defined intervals.
Say 20 degrees every 20 frames. Ideally the movement will be easy easable too.
Any ideas
Thanks
Chris
Jeffrey Lejune replied 12 years, 9 months ago 3 Members · 10 Replies -
10 Replies
-
Filip Vandueren
May 24, 2010 at 1:46 pmHi there,
there is a way to do this all in expressions, but I think it would be difficult to tweak.
I think the easiest way would be to keyframe one rotation, including easing and a pause, then using the loopOut() expression:
for example:
set a keyframe at time 0, rotation0
set a keyfame at time 10 frames, rotation 20
set a third keyframe at time 20 frames, also rotation 20.easy-ease the first two keyframes
now add this expression to the rotation:
loopOut(“offset”);
it’s a very handy way of looping keyframes, I think introduced in CS3.
Where a normal loopOut(“cycle”), would repeat all the keyframes continuously (so it would always reset to 0°), the “offset”-variant, actually adds the last reached value to each subsequent repetition. Just what we need here.Bonus:
If you need to start/stop/keyframe this loop, a very versatile way to do this would be to add 2 expression controls:
a slider called “t”
and an angle called “r”copy the keyframes and expression of rotation to the “r”-angle control.
erase the original keyframes and expression from the rotation, and add this expression to rotation:
effect(“r”)(“Angle”).valueAtTime(effect(“t”)(“Slider”));
now we can keyframe the “t” slider like this:
at time = 1s set t to 0
at time= 5s set time to 4now the layer will start and stop rotating. The advantage of keyframing t is, you can easily start/stop multiple times, slow down or even go backwards. All using ease-ing if you’d like.
Hope that was all clear.
-
Criis Daw
May 24, 2010 at 7:58 pmThanks for your help.
I have CS3 but i cant see loopout (offset) in he drop down.
Will it work if I type it ?
guess i’ll find out
cheers
-
Jeffrey Lejune
August 3, 2013 at 8:55 pmThis was helpful so I wanted to say thanks?
One question is why you you selected the values of 0 at 1s and 4 at 5s?
Does it have something to do with the fact that the original time of the rotation from the previous explanation was 1 sec based on 30 fps?
So you get 4 rotations btwn 1s and 5s because of the 1 sec key framed looped animation. When I changed the value at 5s to 2 I got 2 rotations.
Just trying to understand the math incase I wanted to stretch things out or compress them.
-
Filip Vandueren
August 3, 2013 at 10:24 pmTo re-iterate:
the angle-control has the original expression and keyframes, looping through some values, but that doesn’t do anything visual.
The expression added to rotation uses the value of slider T to look up what value the angle-control has at time=TYou can keyframe “slider T” however you like, faster, slower, start/stop whatever.
In my example,
Nothing would happen for 1 second.
Between 1-5 seconds we are reading the values the angle-control had between 0 and 4 seconds.
Because the keyframes are 4 seconds apart and their values are also 4 seconds apart, the rotation will be “real-time”, but you have a lot more options…clear ?
-
Jeffrey Lejune
August 3, 2013 at 10:41 pmI’m getting it. Writing out comments of my observations on different iterations of the effect on duplicate layers helps.
I’m enjoying experimenting with the Angle control keyframes (timing & easing) as well as the value graph easing for the slider t control effect.
Super helpful. Thanks for the lesson!
-
Jeffrey Lejune
August 3, 2013 at 11:00 pmAfter a 2nd look through your 2nd explanation I also now understand why T would never work as a negative value bc the Timeline would never be have a negative value…. You’re looking for what the angle would be at a certain time based on that loop. We can’t go back past time of 0…. right? You can go from 0 to 1, etc… as well as going from 2 to 1 to 0 to get the rotation to go the other way.
but time travel to before the timeline start’s (negative value of T) isn’t possible… Hah!
-
Filip Vandueren
August 4, 2013 at 8:12 amValues before time 0 are absolutely possible!
Just grab a group of keyframes (or a layer) and drag them to the left: they can exist before time 0 (they’re just hard to edit after you’ve put them there 🙂 )If values exist before 0, valueAtTime() has no problem getting them. It’s just that the expression on te angle-control is creatig extra values after the existing keyframes (hence loopOut)
The angle control could have a different expression that also creates values before time 🙂 -
Jeffrey Lejune
August 4, 2013 at 8:35 amAhh… I see your point and thanks for the further explanation. Based on that I shifted the layer left past time 0 and then began to see results when I changed T to a negative.
The only limit at this point i see is how far back in time (left) I shift the layer or the keyframes for Angle. For example the beginning of the layer (or just the key frames for Angle) is shifted to a time of -20. I don’t see a result when manipulating T lower than -20.
So now I’m curious about your last statement:
“The angle control could have a different expression that also creates values before time :-)”
I’m not sure how to formulate that expression but would interested to know how to get it to output all the way to -infinity time. Not for a particular reason at the moment but there could be a use somewhere down the road.
-
Filip Vandueren
August 4, 2013 at 9:25 amAt it’s simplest form (assuming the first keyframe is at time=0)
if (time<0) {
loopIn("offset");
} else {
loopOut("offset");
}
This version does some more checking to make sure it works properly in all conditions:
if (numKeys>0) {
t1=key(1).time;
if (time -
Jeffrey Lejune
August 4, 2013 at 7:18 pmThanks for the expression script examples. I see your point how an if/then statement keeps it simple and to switch the command based on the condition.
I have experience writing AS3 OOP for web mograph with flash back in the day. Sometimes I feel like it’s hard for me to apply knowledge of simple programming over to AE expressions. Slight differences in syntax and the fact that I don’t know all what I can manipulate through code just yet. I’m slowly coming around though.
Your insights have helped!
Reply to this Discussion! Login or Sign Up