- Home /
can an animation be blended between two frames?
can an animation be blended between two frames?
I need to be able to pause an animation at a precise frame or fraction of the way through the animation. I have been able to do this, for example to pause the animation 20% of the way through I do something like,
framefrac = 0.20;
animation.Play("someanim");
animation["someanim"].enabled = true;
animation["someanim"].weight = 1.0f;
animation["someanim"].time = framefrac*animation["someanim"].length;
animation["someanim"].speed = 0; //to make the animation pause
What I also need to do is blend between two frames and pause the result. How would I, for example show a frame which is blended between 20% of the way through "someanim" and 70% of the way through "someotheranim"
Thanks in advance for your help (am new to Unity)
Format your code or no one will answer the question
If you don't know how, watch the tutorial video on the right
Answer by Benproductions1 · Jul 05, 2013 at 09:11 AM
Hello,
Time and weight are 2 completely different things in the Unity animation system.
While time is obvious, think of weight as how much of this do I want.
If you have 2 animations, weighted at 0.2 and 0.8, then one animation will have 20% influence on the bones, while the other one will have 80% influence.
Weights should always add up to 1 (or things start breaking)
If you want 2 animations, "blended" at 30:70 and at certain times:
var animation1:String;
var animation2:String;
var animation1Time:float;
var animation2Time:float;
var animation1Weighting:float;
var animation2Weighting:float;
function Start() {
//Enable animations
animation[animation1].enabled = true;
animation[animation2].enabled = true;
//Pause animations
animation[animation1].speed = 0;
animation[animation2].speed = 0;
//Set the time of the animations
animation[animation1].time = animation1Time;
animation[animation2].time = animation2Time;
//Set weighting of the animations
//Since you seem to like percentages, I normalized the values as well
//Just in case you use 20:70
var magnitude:float = (animation2Weighting + animation1Weighting);
animation[animation1].weight = animation1Weighting/magnitude;
animation[animation2].weight = animation2Weighting/magnitude;
}
Hope this helps,
Benproductions1
Thanks. That really does help and works just how I hoped it would. It seems I never need to call playanimation or blend of any kind. I do wonder if I change, say, animation2 on the next update loop if I then would have to set enable to false for the old animation2 that was enabled in the previous iteration.
That depends on what you want the animation to do. An animation can still run, even if it's weight is 0 and it's not actually applied. If you want the animation to stop however, setting enabled
to false
is the manual way to go :)
(You could also call .Stop
)
Your answer
![](https://koobas.hobune.stream/wayback/20220613105450im_/https://answers.unity.com/themes/thub/images/avi.jpg)