Skip to main content
Tolomuco-Daniel
Participating Frequently
May 10, 2024
Answered

I have t

  • May 10, 2024
  • 3 replies
  • 651 views

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];

This topic has been closed for replies.
Correct answer Dan Ebberts

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

3 replies

Tolomuco-Daniel
Participating Frequently
May 10, 2024

@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.

Dan Ebberts
Community Expert
Community Expert
May 10, 2024

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?

Tolomuco-Daniel
Participating Frequently
May 10, 2024

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?

Dan Ebberts
Community Expert
Community Expert
May 10, 2024

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)
Mylenium
Legend
May 10, 2024

Fix the last line to only be [s].

 

Mylenium