Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions How to script a bounce using layer in point ?

  • How to script a bounce using layer in point ?

    Posted by Bentsi Beberashvili on January 1, 2023 at 6:18 pm

    I’ve found a few different scripts for the bounce but i’m trying to make basic presets based on the layer in point and out points using sliders to determine the travel pixels on the x,y,z points. Meaning I want to quickly put my preset on a layer, type the distance to travel to get to the [x,y,z] values of the layer. So if I punch in -300 on the y axis it should start up 300 pixels and travel the duration I plug into another slider. I’ve got this going with keyframes but was hoping to do it without using keyframes.

    I found this code but i’m still a novice when it comes to coding so I’m not sure how to properly parse this or if this would even work, still a nifty script from https://motionscript.com/articles/bounce-and-overshoot.html:

    elev = degreesToRadians(75);
    v = 1900;
    e = .7;
    f = .5;
    g = 5000;
    nMax = 9;
    tLaunch = 1;
     
    vy = v*Math.sin(elev);
    vx = v*Math.cos(elev);
    if (time >= tLaunch){
      t = time - tLaunch;
      tCur = 0;
      segDur = 2*vy/g;
      tNext = segDur;
      d = 0; // x distance traveled
      nb = 0; // number of bounces
      while (tNext < t && nb <= nMax){
        d += vx*segDur;
        vy *= e;
        vx *= f;
        segDur *= e;
        tCur = tNext;
        tNext += segDur;
        nb++
      }
      if(nb <= nMax){
        delta = t - tCur;
        x = d + delta*vx;
        y = delta*(vy - g*delta/2);
      }else{
        x = d;
        y = 0;
      }
      value + [x,-y]
    }else
      value
    Dan Ebberts replied 3 years, 4 months ago 3 Members · 3 Replies
  • 3 Replies

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