Copy link to clipboard
Copied
I have to update a project made by another workmate, he is not available, he have this character hair bouncing a bit when it moves the head and the hair have this expression and show me this error
and this is the 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
freq = 0.2;
amp = 80;
s= amp*Math.sin(freq*time*2*Math.PI);
[s,s];
Depending on how you have your keyframes set up, this might be more what you're looking for:
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 = speedAtTime(key(n).time - .001);
w = freq*Math.PI*2;
value + amp*(Math.sin(t*w)/Math.exp(decay*t)/w);
}else
value
Copy link to clipboard
Copied
Fix the last line to only be [s].
Mylenium
Copy link to clipboard
Copied
It looks like that's a scale expression. It should work for rotation if you replace the last two lines with this one:
amp*Math.sin(freq*time*2*Math.PI)
Copy link to clipboard
Copied
@Mylenium and @Dan Ebberts Thanks both of you. I'm still struggling learning expressions. both solutions work to eliminate the error, but both solutions set and awkard angle in the layer I can't change, the hair ends almos vertical hidden behind the character head.
Copy link to clipboard
Copied
Actually, looking at it a little closer, it looks like this expression started out as one thing and has been modified, inconsistently, a time or two so that it's hard to say what the original intention was. How do you want it to work?
Copy link to clipboard
Copied
The top piece of hair is anchored on one side of the head, bounce a bit with the head movements, but actually is a very subtle movement... So I render it without it to meet the time, client don't even notice it, but I get intrigued on how it was made and how to fix it. I have a few rotation keyframes on the movement and the expression it's supposed to help make ot more bouncy... sadly I can share the project 'cause. any of idea?? may be a completely diff expression?
Copy link to clipboard
Copied
imagine something like this... left is the initial state and position of the anchor.... after I apply any of your solutions (both give the same result), i looks like the image on the right... and it doesn't move.
Copy link to clipboard
Copied
Depending on how you have your keyframes set up, this might be more what you're looking for:
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 = speedAtTime(key(n).time - .001);
w = freq*Math.PI*2;
value + amp*(Math.sin(t*w)/Math.exp(decay*t)/w);
}else
value
Copy link to clipboard
Copied
It works perfectly!!!! thanks