Skip to main content
Participating Frequently
March 2, 2026
Question

Using a Bounce Expression?

  • March 2, 2026
  • 1 reply
  • 20 views

I animated a .png of an item falling, and rotating as it falls until it hits the floor. After the animation ended, I moved the CTI a few frames ahead and rotated it a bit to add a new keyframe, and moved the CTI again and rotated it again to make it seem more like a bounce when it hit the ground. I want to make the bounce seem a bit more natural. I spent some time online and I read about Expressions, and I copied some Bounce Expression that I found, and I want to paste it so I press alt and clicked on the Stopwatch for  Rotation to paste the Expression since this is the last thing that I added to the animation. The Expression editor opens with

transform.rotation

When I paste the following Bounce Expression after this it just gives me an error.

 

“This project contans an expression error: error 1 of 1. What am I doing wrong? Thanks in advance!

 

e = .5;

g = 20000;

nMax = 9;

n = 0;

if (numKeys > 0){

n = nearestKey(time).index;

if (key(n).time > time) n–;

}

if (n > 0){

t = time – key(n).time;

v = -velocityAtTime(key(n).time – .001)*e;

vl = length(v);

if (value instanceof Array){

vu = (vl > 0) ? normalize(v) : `{`0,0,0`}`;

}else{

vu = (v < 0) ? -1 : 1;

}

tCur = 0;

segDur = 2*vl/g;

tNext = segDur;

nb = 1; // number of bounces

while (tNext < t && nb <= nMax){

vl *= e;

segDur *= e;

tCur = tNext;

tNext += segDur;

nb++

}

if(nb <= nMax){

delta = t – tCur;

value + vu*delta*(vl – g*delta/2);

}else{

value

}

}else

value

 

    1 reply

    Dan Ebberts
    Community Expert
    Community Expert
    March 2, 2026

    It looks like some of the syntax got mangled somewhere along the line. This should get rid of the error(s), but I’m not sure if it does what you expect:

    e = .5;
    g = 20000;
    nMax = 9;
    n = 0;
    if (numKeys > 0){
    n = nearestKey(time).index;
    if (key(n).time > time) n--;
    }
    if (n > 0){
    t = time - key(n).time;
    v = -velocityAtTime(key(n).time - .001)*e;
    vl = length(v);
    if (value instanceof Array){
    vu = (vl > 0) ? normalize(v) : [0,0,0];
    }else{
    vu = (v < 0) ? -1 : 1;
    }
    tCur = 0;
    segDur = 2*vl/g;
    tNext = segDur;
    nb = 1; // number of bounces
    while (tNext < t && nb <= nMax){
    vl *= e;
    segDur *= e;
    tCur = tNext;
    tNext += segDur;
    nb++
    }
    if(nb <= nMax){
    delta = t - tCur;
    value + vu*delta*(vl - g*delta/2);
    }else{
    value
    }
    }else
    value

     

    Participating Frequently
    March 2, 2026

    Thank you. Is there a better/easier way to create the effect of a more natural bounce after an object lands on the ground based on what I described in my initial post?

    Dan Ebberts
    Community Expert
    Community Expert
    March 2, 2026

    Your initial description confused me because you talked about adding the bounce expression to the rotation property, where I would normally expect to see it applied to position, so I’m having trouble picturing what your desired result would look like.