- Home /
I want to blend two animations
Hello,
I have problems blending two animations, I want to start the animations to the same time. I tried to use AnimationState.layer but I don't know why is not working my script.
I want to blend (Key and ShaftLockButton) animations.
Any advice.
Thanks in advance for your help.
var Skin_tool: GUISkin ;
var Skin_battery: GUISkin ;
var Skin_key: GUISkin ;
var Skin_power: GUISkin;
var beep : AudioClip;
var other : GameObject;
function OnGUI (){
//Make the OnOffSwitch button
GUI.skin = Skin_power;
if (GUI.Button(Rect(770,227,80,52),"")){
audio.PlayOneShot(beep);
animation.PlayQueued ("OnOffSwitch");
}
//Make the ShaftLockButton button
GUI.skin = Skin_lock;
if (GUI.Button(Rect(770,282,80,56),"")){
audio.PlayOneShot(beep);
animation.PlayQueued ("ShaftLockButton");
}
//Make the Tool button
GUI.skin = Skin_tool;
if (GUI.Button(Rect(770,341,80,68),"")){
audio.PlayOneShot(beep);
animation.PlayQueued ("Tool");
}
//Make the Key button
GUI.skin = Skin_key;
if (GUI.Button(Rect(770,412,80,35),"")){
audio.PlayOneShot(beep);
animation["Key"].layer = 1;
animation["ShaftLockButton"].layer = 1;
animation.SyncLayer(1);
}
//Make the Battery button
GUI.skin = Skin_battery;
if (GUI.Button(Rect(770,450,80,38),"")){
audio.PlayOneShot(beep);
animation.PlayQueued ("Battery");
}
}
@script RequireComponent(AudioSource)
Answer by Owen-Reynolds · Dec 21, 2012 at 04:40 PM
Blending is like averaging -- add them up and divide by 2. For animations, play them both at 1/2 weight, and the system will add them together.
So, somewhere you should have animation["key"].weight=0.5;
The animation system wants to play 1 animation per layer. To blend two, but them on different layers, and set the one on the highest layer to weight 0.5. The system will automatically give the other one the remaining 0.5.
SynchLayer, which you have now, changes them both to be the same length. If they are the same length, it does nothing. If they are on different layers, you can synch yourself by just comparing times. If KEY takes 1 sec and SHAFTLOCK takes 1.5 secs, set the speed of SHAFTLOCK to 0.6666. Now it also take 1 sec (this is all SynchLayer does -- set speeds.)
If you want to keep them on the same layer, you can't use animation.Play
commands. They are set to quit other animations on the same layer. A trick is to use animation.enabled=true
, instead of Play.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
How to mix animations? 3 Answers
Moving an object on elliptical path 1 Answer
How to setup animtion????? 2 Answers