Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects how can I set this expression up to stop when it lands on a surface.

  • how can I set this expression up to stop when it lands on a surface.

    Posted by Chris Behl on September 7, 2015 at 10:27 am

    A falling leaf can be a pretty complicated simulation – sometimes they just
    fall gently, sometimes they do barrel-rolls, sometimes glide back and forth, or
    any combination. These expression roughly simulate the glide back and forth
    variation. I tried this on a 3D solid positioned above the camera view,
    oriented with Z pointing down and Y pointing in the positive Z direction
    (orientation [90,0,0]).

    Then I added these three expressions:

    POSITION:

    yVelocity = 200; //pixels per second
    oscFreq = 1.5; //oscillations per second
    oscDepth = 35; //oscillation depth (pixels)
    drift = 25; // drift (wind?) (pixels per second: – = left, + = right)

    value + [oscDepth*Math.sin(oscFreq*Math.PI*2*time) + drift *time,
    yVelocity*time,0]

    Z ROTATION:

    seed_random(index,true);
    random(360);

    Y ROTATION:

    oscFreq = 1.5;
    maxTilt = 15; //degrees

    maxTilt*Math.cos(oscFreq*Math.PI*2*time)

    If you edit the parameters, you need to make sure that the oscillating
    frequency is the same in both the position and y-rotation expressions (or map
    it to a slider control). If you wanted to apply this to a bunch of leaves,
    you’d want to introduce some randomness into the various parameters along with
    a random starting phase.

    Kalleheikki Kannisto replied 10 years, 10 months ago 2 Members · 3 Replies
  • 3 Replies
  • Kalleheikki Kannisto

    September 8, 2015 at 7:34 am

    So, do you want to know how to gracefully stop it when it hits a certain y position?

  • Chris Behl

    September 8, 2015 at 9:41 am

    Yes please.

  • Kalleheikki Kannisto

    September 9, 2015 at 1:23 pm

    Here’s my approach:

    Add a layer named “control” with two sliders, “ground” and “ease”. Set ground to the desired y coordinate for the ground plane and ease to how many pixels above the ground plane you want to start the transition.

    Then use this for the Position value expression

    yVelocity = 200; //pixels per second
    oscFreq = 1.5; //oscillations per second
    oscDepth = 35; //oscillation depth (pixels)
    drift = 25; // drift (pixels per second: - = left, + = right)
    ground = thisComp.layer("control").effect("ground")("Slider");
    ease = thisComp.layer("control").effect("ease")("Slider");

    y_origin = transform.position.valueAtTime(0)[1];
    x_position = transform.position[0];
    y_position = y_origin+yVelocity*time;
    z_position = transform.position[2];

    if (y_position>ground-ease && y_positionground){
    y_position=ground;
    oscDepth = 0;
    }

    y_distance = y_position-y_origin;

    pos = [x_position+oscDepth*Math.sin(oscFreq*Math.PI*2*time) + drift*y_distance/100, y_position, z_position];
    pos

    and this for the Y Rotation


    yVelocity = 200; //pixels per second
    oscFreq = 1.5;
    maxTilt = 15; //degrees
    ground = thisComp.layer("control").effect("ground")("Slider");
    ease = thisComp.layer("control").effect("ease")("Slider");

    y_origin = transform.position.valueAtTime(0)[1];
    y_position = y_origin+yVelocity*time;

    if (y_position>ground-ease && y_positionground){
    maxTilt = 0;
    }

    tilt=maxTilt*Math.cos(oscFreq*Math.PI*2*time);
    tilt

    Now the animation will smoothly stop at the ground place regardless of starting position.

    If you duplicate this to multiple layers the oscillation and motion will be synchronized, so you’ll want to add other random values for some of the variables. Or change the settings for each layer.

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