Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Expression Needed: Rotation based on Position!!!

  • Expression Needed: Rotation based on Position!!!

    Posted by Shirak Agresta on April 24, 2007 at 5:32 am

    Okay, basically what I’m trying to do is this:

    I’ve got an object (SHIRT) parented to a second layer (RACK) so that where the RACK moves the SHIRT moves with it. No problem. BUT, I need the SHIRT to rotate on its X and Z axis (everything’s a 3D layer) based on the movement/position of the RACK so when the RACK reaches its end point keyframe of movement the SHIRT’s rotation decays (rather quickly) to its default position.

    To make things harder (maybe?), I actually have 3 SHIRTS on the RACK, and they can’t intersect each other OR the RACK layer, ergo, the rotation(s) need to have limits.

    Dan, you’ve been such a help before, I hope you (or anyone else for that matter) can help me now! I have a deadline (of course) in 3 days so if at all possible, a quick reply would be awesome! I feel like it’s on the tip of my brain, but I can’t quite figure this out.

    Thanks!

    Julius Caesar and the Roman Empire couldn’t conquer the blue sky.

    Filip Vandueren replied 19 years ago 2 Members · 3 Replies
  • 3 Replies
  • Filip Vandueren

    April 24, 2007 at 11:22 am

    I’ve done something like this before but don’t have time to dig up the code right now.
    I can work on it tonight (CET timezone), and post a project and the expressions.

    Basically it is looking at the velocity by which the rack moves, applying inertia to this and figuring out to what angles the difference in position between where the shirt is now and where it ‘wants’ to be by lagging behind.
    Inertia of course can only be achieved by calculating every frame that has gone before the current time. As a bonus you get a springy swingy motion.
    The ‘collision detection’ should be either not necessary depending on the spacing of the shirts, or a bit difficult to code.

    You can see a little testrender I did here:

    https://forums.creativecow.net/readpost/227/7118?

    I’ll get back to you with the source files.

  • Shirak Agresta

    April 25, 2007 at 12:14 am

    Great, thanks so much. I look forward to the code! The shirts are supposed to be hard, basically like swinging cards or cardboard, so I’m not worried about deformation or anything like that. I just don’t want them to intersect. When I get home I’ll post a still (if I can) of the image I’m using.

    I couldn’t see the example you have, not sure if it’s my flash player or what.

    Thanks again!

    Julius Caesar and the Roman Empire couldn’t conquer the blue sky.

  • Filip Vandueren

    April 25, 2007 at 12:27 pm

    Hi,

    here’s the project:

    https://www.vandueren.be/forumstuff/inertia/inertia-shirts.aep

    You can easily control the stiffness and springiness and amount by which the shirts rotate with a few sliders I placed on a control Null.

    Here’s the code (note that my solids have orientation [270,0,0]:

    for X rotation:

    inertia = thisComp.layer("CONTROLLER").effect("inertia")("Slider");
    stiffness = thisComp.layer("CONTROLLER").effect("Stiffness")("Slider");
    mass=thisComp.layer("CONTROLLER").effect("mass")("Slider");

    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) { return parent.position.velocityAtTime(t)[2]/-mass; }

    for Z rotation:

    inertia = thisComp.layer("CONTROLLER").effect("inertia")("Slider");
    stiffness = thisComp.layer("CONTROLLER").effect("Stiffness")("Slider");
    mass=thisComp.layer("CONTROLLER").effect("mass")("Slider");

    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) { return parent.position.velocityAtTime(t)[0]/mass; }

    This is what it looks like:


    I think I added a bit too much springiness in my example, but that's easily fixed with the sliders.

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