Highlighted

## Overshoot/Bounce Back Expressions Mess up Orient Along Path

New Here ,
Oct 14, 2020

Copied

Hi,

I have a series of layers animating along a path. I have each one oriented along the path. I'm trying to add bounce back/overshoot expressions, but this creates crazy unwanted effects with the orientation, causing the layers to switch direction randomly, or suddenly at the end.

I don't have a very deep understanding of expressions, but I definitely don't plan on creating this bounce back manually.

Any advice is appreciated. The screenshot shows my animation without expressions. Here are the expressions I'm trying to use:

```Keyframe Overshoot Expression:

freq = 3;
decay = 5;

n = 0;
if (numKeys > 0){
n = nearestKey(time).index;
if (key(n).time > time) n--;
}
if (n > 0){
t = time - key(n).time;
amp = velocityAtTime(key(n).time - .001);
w = freq*Math.PI*2;
value + amp*(Math.sin(t*w)/Math.exp(decay*t)/w);
}else
value```

```Keyframe Bounce Back Expression:
e = .7;
g = 5000;
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  ```

TOPICS
Expressions, Scripting

Views

50

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

## Overshoot/Bounce Back Expressions Mess up Orient Along Path

New Here ,
Oct 14, 2020

Copied

Hi,

I have a series of layers animating along a path. I have each one oriented along the path. I'm trying to add bounce back/overshoot expressions, but this creates crazy unwanted effects with the orientation, causing the layers to switch direction randomly, or suddenly at the end.

I don't have a very deep understanding of expressions, but I definitely don't plan on creating this bounce back manually.

Any advice is appreciated. The screenshot shows my animation without expressions. Here are the expressions I'm trying to use:

```Keyframe Overshoot Expression:

freq = 3;
decay = 5;

n = 0;
if (numKeys > 0){
n = nearestKey(time).index;
if (key(n).time > time) n--;
}
if (n > 0){
t = time - key(n).time;
amp = velocityAtTime(key(n).time - .001);
w = freq*Math.PI*2;
value + amp*(Math.sin(t*w)/Math.exp(decay*t)/w);
}else
value```

```Keyframe Bounce Back Expression:
e = .7;
g = 5000;
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  ```

TOPICS
Expressions, Scripting

Views

51

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 14, 2020 0
2 Replies 2
Oct 14, 2020

Copied

Orient along a path does exactly that. The layer orientation is controlled by the motion along the path so if the direction of the motion changes because of the expressions so does the orientation. There is no bug.

What you have to do is set up a parallel path using a null that is not oriented to the path, adjust the timing of the duplicate path, and then use Vector Math to make the layer with bounce and overshoot look at the reference path. I don't have the time to set up a sample comp with some expressions right now, but that is the general workflow.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 14, 2020 0
LATEST
Guide ,
Oct 14, 2020

Copied

You could try turning off auto orient and using this rotation expression:

``````p = position;
n = 0;
if (p.numKeys > 0){
n = p.nearestKey(time).index;
if (p.key(n).time > time) n--;
}
if (n > 0){
t = p.key(n).time;
}else{
t = p.key(1).time;
}
v = p.velocityAtTime(t);