Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Ponytail physics

  • Posted by Jaakko Rinne on March 22, 2009 at 9:38 pm

    Hi,

    I’m looking to create animated characters with hair that moves somewhat realistically with their keyframed heads. The hair will only need to be a single layer (like a stiff ponytail, or a single lock of hair in front of the face). I’m fairly sure I already found what I’m looking for here but I’m not sure how to apply that. I’m pretty much a complete newbie when it comes to expressions (I mean, I can do the odd jitter-effect with a wiggler expression, but that’s about it).

    The animation in this thread also looks like it could be what I’m looking for, but I only need the pendulum effect in 2D.

    Any help would be appreciated.

    EDIT: I was able to somewhat mangle the 3d shirt physics expression to my test project, but the ponytail seems to be going in front of the head, not lagging behind it.

    Zonkin replied 15 years, 12 months ago 3 Members · 5 Replies
  • 5 Replies
  • Filip Vandueren

    March 22, 2009 at 11:32 pm

    You first have to define in ‘quantifiabe amounts’ what you want the ponytail to do,
    then convert that to an expression, and you can then put that expression in my calcValue function to add latency and springiness to it.

    the expression would probably be applied to rotation, so here are some pointers:
    For example:
    if the head/person moves forward, the ponytail should rotate slightly up
    if the head/person moves backward, the ponytail should rotate slightly down
    if the head/person moves down, the ponytail should rotate up
    if the head/person moves up, the ponytail should rotate down
    if the head rotates, the ponytail wants to keep pointing ‘down’

    Think about that first, get back to me and we’ll work from there.

  • Filip Vandueren

    March 23, 2009 at 12:30 am

    This might be a good starting point:

    the start of the pony tail (anchorpoint) is parented to the head, so it will move along with it’s parent.
    The end of the pony tail lags behind via rotation.

    So it wants to rotate so it would point at where the end of the ponytail was one frame ago.


    inertia = 0.5;
    stiffness = 0.25;

    lagValue = calcValue(0);
    f= thisComp.frameDuration;
    will=0;

    for (t=0; t<=time; t+=f) { delta = calcValue(t) - lagValue; will = will * inertia + delta*stiffness ; lagValue +=will } lagValue; function calcValue(t) { p1=toComp(anchorPoint,t); p2=toComp(anchorPoint,t-thisComp.frameDuration)+[0,100]; x=p2[0]-p1[0]; y=p2[1]-p1[1]; r=radiansToDegrees(Math.atan2(y,x))-90 - parent.rotation.valueAtTime(t); return r; }

    this will give lagging on X and Y motion, and parent rotation:

  • Jaakko Rinne

    March 23, 2009 at 6:05 pm

    Thanks for the replies, Filip.

    To “quantify” what I would like the ponytail rotation to do:
    – Rotate slightly clockwise if the head is moving right and rotate slightly counterclockwise if the head is moving left. The amount of rotation should depend on the speed the head is moving at.
    – Rotate ponytail “down” if the head moves up. Rotation speed should depend on the speed the head is moving at.
    – Rotate ponytail “up” if the head moves down. The amount of rotation should depend on the speed the head is moving at.
    – Rotate left and right and slowly stop rotations like a pendulum when the head stops after movement.
    – Rotate left or right as if with momentum if the head suddenly changes its movement direction.

    The expression you posted already has most of these effects, but doesn’t seem to take into account if the head is moving downwards quickly (the ponytail just hangs down). I would also like for the ponytail to have a bit more “swing” to it, that is, bigger rotation. When the head moves sideways fast, the ponytail should go up to around a 90 degree rotation in either direction and when the head moves down fast, the ponytail should possibly do up to 180 degrees.

    I think I understand what the values for inertia and stiffness affect, but which part of the expression should I edit to increase the amount of rotation? I should probably create an effect control slider for this, like I did for inertia and stiffness.

  • Filip Vandueren

    March 24, 2009 at 1:53 am

    Hi,

    inertia is how long the ‘pendulum keeps swinging’, and should not go above 1, becaus ethen you get a ‘perpetuum mobile that keeps going faster’

    stiffness is how hard the spring is, the softer it is, the slower it swings back and fro.

    I tweaked the expression a little, and this one, though a bit simpler seems to work better:


    inertia = 0.8;
    stiffness = 0.25;

    lagValue = calcValue(0);
    f= thisComp.frameDuration;
    will=0;

    for (t=0; t<=time; t+=f) { delta = calcValue(t) - lagValue; will = will * inertia + delta*stiffness ; lagValue +=will } lagValue-parent.rotation; function calcValue(t) { p1=toComp(anchorPoint,t); p2=toComp(anchorPoint,t-thisComp.frameDuration); x=p1[0]-p2[0]; y=p1[1]-p2[1]; if (y>0) {
    y=y*5; // make *5 variable ?
    } else {
    y=y*0; // negative Y speed has no effect
    }

    r=x*2 + y; // make *2 variable

    return r;
    }

    you can substitute the *2 and the *5 with slider values, but be sure to include slider.valueAtTime(t); basically everything inside the calcValue function needs to be in function of time t

    I've disabled the rotation when moving up, because it didn't seem right to me. but you can renable and see if you like it, or get different sliders to control up/down/left/right influence this way.

    I moved parent.rotation compensation out of the calcValue function, becasue the subtle effect wil allready be picked up by the fact that the anchorpoint also moves when the head rotates.

    Any limits you want to put on rotation, I would try to tweak with the * multipliers, but you can set an absolute limit of the output by changing the line "return r" to something like return clamp(r,-5,5);
    note that this will not limit the rotation to -5 and +5, just the 'will of the layer to change it's rotation' to a max of +-5, the actual maximum will be depended on the inertia and stiffness value, and can be more.

    be sure to post your endresult ! I'm looking forward to seeing this in action.

  • Zonkin

    May 10, 2010 at 3:28 pm

    I love this script! And I’m planning to use it in a professional project. But it only seems to take into the account the rotation of the parent to calculate the “down” direction.

    I’ve made two nulls, the top one has this script on it, and the bottom one controls a puppet point on the hair. It works fairly nicely.

    Moving the body of the rig around works great, and rotating the face too, the problem is getting a nice settle position when animating rotation higher in the hierarchy, like the neck or torso. Is there a fix to take into account all the rotations of the parents in the comp?

    I’m guessing this has something to do with it:
    lagValue-parent.rotation;

    Help is greatly appreciated, and I’ll pos a link to the project, if the pilot ever finishes 😉

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy