0
\$\begingroup\$

I have two layers of animation and I'm trying to SMOOTHLY transition between these two layers when I click a button.

public void OnButtonClicked(){
animator.SetLayerWeight(layerIndex, 1f);
}

For some reasons I don't know, the animation is not smooth at all. It looks really bad when I click the button and the new animation that I'm setting its layer weight starts

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

You must interpolate the animator.SetLayerWeight across multiple steps.

float LayerWeightTarget = 0;
float CurrentLayerWeightTarget = 0;
public void OnButtonClicked()
{
   LayerWeightTarget = 1f;
}
public void Update()
{
   if(CurrentLayerWeight != LayerWeightTarget)
   {  
      CurrentLayerWeight = (LayerWeightTarget - CurrentLayerWeight) * 0.125f;
      // Adjust value(.125f) to your preferred speed. not linear, but fast and convergent.
      Targetanimator.SetLayerWeight(layerIndex, CurrentLayerWeight);
   }
}
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .