Activity › Forums › Adobe After Effects Expressions › Controlling the speed of a rotation
-
Controlling the speed of a rotation
Posted by Nicolas Plaire on May 10, 2010 at 5:49 amHi everyone!
I’ve been trying to find a way to control the speed of the rotation of a layer. I’ve been foolishly thinking that a simple time*Speed [speed being linked to a slider that I keyframe] would do. But it doesn’t, when I want to change the speed from 90 to 40 for example, my rotation goes backward first instead of simply slowing down.
Or when I want to speed up my layer, from 90 to 500, instead of getting just faster, it becomes crazy, do several complete rotation, having a speed over 2000] before settling to 500. This is not, obviously, what I want. So, is there any solution, any way we could setting the speed or the velocity of a layer rather than setting the rotation?Thanks
Dan Ebberts replied 12 years, 8 months ago 6 Members · 12 Replies -
12 Replies
-
Dan Ebberts
May 10, 2010 at 2:28 pmChanging speeds is one of those things that can be pretty tricky with expressions. One way to do it is to do a frame-by-frame integration (accumulation) of your speed control. Here’s an example with a slider named “rpm”:
slider = effect(“rpm”)(“Slider”);
accum = 0;
f = timeToFrames(inPoint);
while (f < timeToFrames()){ accum += slider.valueAtTime(framesToTime(f)); f++; } accum*thisComp.frameDuration*60 Dan -
Nicolas Plaire
May 11, 2010 at 4:26 amThanks… I’ll try to see how it work [because after that, I’ll try to link that rotation speed to an audio layer].
Very helpful, thanks!
-
Greg Digenti
October 1, 2010 at 6:03 pmThis seems like it could have been what I was looking for in my attempts to slow a rotation, but there seems to be a lot wrong with it. There isn’t an opening curly bracket, or a closing parenthesis, and one line is “while (f” and just ends like that.
-
Greg Digenti
October 1, 2010 at 6:09 pmWait, never mind! How strange, the first time I viewed this thread, there was a lot of things missing from your code, then when I re-loaded the page, the missing parts showed up! Must be a Cow bug. Works great, thanks!
-
Paul Roper
January 5, 2012 at 8:51 pmA response to a post lost in the mists of time…
I came across this while trying to fix the same problem the original post highlighted. So I used Dan’s expression, which worked perfectly…except there’s no motion blur!…(and yes, I do have the motion blur switch on!)
My layer rotates beautifully, but no matter how fast it goes, no blur occurs. To check things, I duplicated the layer, deleted the expression and did an old-fashioned keyframe rotate animation, and lo and behold we have motion blur, so it’s not a problem with my comp.
I’ve made a fix using Radial Blur linked to the speed slider which works fine.
Anyone else come across this possible bug? I guess it’s something to do with the cumulative nature of the rotation expression. Maybe.
-
Jim Darski
April 9, 2013 at 6:12 pmThanks so much Dan! This works really well.
Just make sure Slider Effect is applied to the rotating layer and renamed it to rpm. (took me a few minutes to figure it out). -
Dave Currie
November 28, 2013 at 4:24 amHello Dan,
I made a camera rig in CS5.5 using a similar expression to your solution here.
You can start from 0 and accelerate, then decelerate back to 0. Here is the position expression I used for that:
pSpeed = thisComp.layer("Easy Camera Controller").effect("XYZ Rig Speed")("3D Point");
pOffset = thisComp.layer("Easy Camera Controller").effect("Camera Rig Position")("3D Point");
accum = 0;
f = timeToFrames(inPoint);
while (f < timeToFrames()){
accum += pSpeed.valueAtTime(framesToTime(f));
f++;
}
accum*thisComp.frameDuration+pOffsetThis works nicely in CS5.5, and I made a modified version for CS5 by splitting the 3D point controls into individual sliders.
Using the same expressions in CC works, but for some reason when I use Element 3D and add a light, it crashes After Effects every time with no error messages.
Here is the expression so far for the CC version but for some reason it always comes up with ‘valueAtTime is undefined’. I need to find the right solution so that AE doesn’t crash with Element, and I still have the same functionality on the rig.
pSpeed = thisComp.layer("Easy Camera Controller").effect("XYZ Rig Speed")("3D Point");
pOffset = thisComp.layer("Easy Camera Controller").effect("XYZ Rig Position")("3D Point");accum = [0,0,0];
f = timeToFrames(inPoint);
while ( f <= timeToFrames()){
accum[0] += pSpeed[0].valueAtTime(framesToTime(f));
accum[1] += pSpeed[1].valueAtTime(framesToTime(f));
accum[2] += pSpeed[2].valueAtTime(framesToTime(f));
f++;
}[accum[0]*thisComp.frameDuration+pOffset[0], accum[1]*thisComp.frameDuration+pOffset[1], accum[2]*thisComp.frameDuration+pOffset[2]]
If you’d like to see the whole rig just let me know and I can send you a copy.
Thank you for any help you can provide!
-
Dan Ebberts
November 28, 2013 at 7:54 amYou need to do the array indexing after valueAtTime(), so, for example, this:
pSpeed[0].valueAtTime(framesToTime(f))
should be like this:
pSpeed.valueAtTime(framesToTime(f))[0]
I don’t know if that’s the only thing wrong, but try fixing it
Dan
-
Dave Currie
November 28, 2013 at 5:47 pmThank you for your help Dan!
This seems to work in CC:
pSpeed = thisComp.layer("Easy Camera Controller").effect("X Y Z Rig Speed")("3D Point");
pOffset = thisComp.layer("Easy Camera Controller").effect("Camera Rig Position")("3D Point");accum = [0,0,0];
f = 0;
while ( f <= timeToFrames(time)){
accum[0] += pSpeed.valueAtTime(framesToTime(f))[0];
accum[1] += pSpeed.valueAtTime(framesToTime(f))[1];
accum[2] += pSpeed.valueAtTime(framesToTime(f))[2];
f++;
}x = accum[0]*thisComp.frameDuration+pOffset[0];
y = accum[1]*thisComp.frameDuration+pOffset[1];
z = accum[2]*thisComp.frameDuration+pOffset[2];[x,y,z]
So my rig is in the scene and I add a solid layer with Element 3D, everything works fine.
The second I add a light to the scene the whole thing crashes – could this have something to do with how CC caches in the background and the frame-by-frame integration in the expression?
I’m pulling my hair out trying to figure this one out!
Thanks again Dan and Happy Thanksgiving!
-
Dan Ebberts
November 28, 2013 at 6:39 pmDoes it crash when you add the light if you don’t have Element applied to the solid?
Dan
Reply to this Discussion! Login or Sign Up