Activity › Forums › Adobe After Effects Expressions › expression : limit a rotation
-
expression : limit a rotation
Posted by Incredible Bud on November 21, 2006 at 12:04 pmhello,
I’ve a 2d Character in 2 seperate layers : the body and the head; I want the head to rotate 30
Incredible Bud replied 19 years, 5 months ago 3 Members · 6 Replies -
6 Replies
-
Mylenium
November 21, 2006 at 6:51 pmNot sure what you are trying to do (people actually do not move the head that much when walking, it’s a mere compensation reaction for pelvis twist up the spine), but why not simply animate one cycle and then use loopOut(“cycle”,0)?
Mylenium
[Pour Myl
-
Incredible Bud
November 21, 2006 at 8:28 pmI’m a beginner with expressions !!
So the cycle seems a good idea. I’ll try it. Thank you.
But i thought that an expression will give me more opportunity to change the rythm of my animation.
my character will appear in different shot, moving differently. (“walking” or “running”)And I thought I could use the same expression for the legs or the arms.
-
Mike Clasby
November 22, 2006 at 3:29 amThis is not related to body movement, but to get a nice head wobble, you could try putting this expression on the z rotation of your head layer:
freq = 7; //oscillations per second
amplitude = 30;
decay = 0; //no decayamplitude*Math.sin(freq*time*2*Math.PI)/Math.exp(decay*time)
Change the freq and amplitude (this is your 30 degrees) to taste.
If you put a slider on the “decay” you can set keyframes, first 0 just before the stop, second 1 (see below for decay values) when you toon stops and then his head will stop rotating in a controlled way. You can add a slider by Effect>Expression Controls>Slider Control, Double click the slider and rename it “Decay”, then highlight (select) the “0” in line 3 and pickwhip that to the slider and you’ll get an expression on line 3 like this:
decay = effect(“decay”)(“Slider”);
You’ll probably need to change the range of the slider by right clicking the slider value, then Edit Value, and make the Slider Range from 0 to maybe 5. Five as decay kills it dead instantly, you need decay values below one to give a slow stop to the rotation.
If you add similar sliders to freq and amplitude you can have total control over you wobble.
You can make a preset and then get this setup in an instant by applying the preset to any new head layer.
The expression is from Dan’s page here:
https://www.motionscript.com/mastering-expressions/simulation-basics-3.html
-
Mike Clasby
November 22, 2006 at 3:58 amI’m soory but I mixed up my expressions, here’s the one I meant to give you:
veloc = 7;
amplitude = 30;
decay = 0//no decayamplitude*Math.sin(veloc*time)/Math.exp(decay*time)
That makes for a much gentler wobble. Ooops, too many pots in the fire.
Still Dan’s, just a variation.
-
Mike Clasby
November 22, 2006 at 8:48 amOK, this is a little hairy, but it seems to work.
Here is an expression to make your head (layer) wobble when the body (layer) has a speed in the z direction greater than zero. Put this on the “head” layer’s z rotation. It reacts to keyframes set for the Body layer’s position, if the body’s Z position changes, the head wiggles. Everything after the Else (line 7) is just looking for a marker on the head layer, then when it finds one, it gives the head’s z rotation a little vibration (that second Amp and Freq controls this vibration). I though that would be nice as a reaction to the stop, otherwise the stop seems a bit abrupt. If you don’t add markers, the wobble will still occur on movement, but not little reaction to the stop. Add the marker ( * on the numeric keypad) to the head layer, where the Body position keyframe comes to a stop. Again these were put together (like Dr Frankenstein) from the corpses of Dan Ebbert’s expressions.
bs = thisComp.layer(“body”).position.speed // speed of the layer “body”
if ( bs > 0){;
veloc = 7;
amplitude = 30;
decay = 0; //no decay
amplitude*Math.sin(veloc*time)/Math.exp(decay*time)
}else{
amp=15; //amplitude (pixels)
freq=7; //frequency (cycles per second)
decay=2.5; //decay time (seconds)
// find previous marker
n = 0; // assume haven’t reached a marker yet
if (marker.numKeys > 0){
n = marker.nearestKey(time).index;
if (marker.key(n).time > time){
n–;
}
}if (n > 0) t = time – marker.key(n).time else t =0;
y = amp*Math.sin(freq*t*Math.PI*2)/Math.exp(decay*t);
value + y
} -
Incredible Bud
November 22, 2006 at 9:56 amThanks a lot.
And of course thanks to DAN. This website seems really interesting.
I’m going to try those expression.The last one may also work for a leg or an arm if I did understand it.
There’s one thing I’don’t get : why are we using an exponential function as a divider ? What does it mean ?
Reply to this Discussion! Login or Sign Up