- Home /
Play an animation just on some parts of the body
I know that I can use layers to set animation prirority and AddMixingTransform to just set animate some parts of a mesh. Unfortunately, it doesn't really work. Everytime I want to crossfade to the walkanimation(that just animates the legs) it also fades the idle animation out but it should keep playing "Idle" and should just overwrite the animation of the legs. What is wrong with the script? I can't find something I miss there
void Start () {
Animationen["Idle"].layer = 2; Animationen["Walk_Weapon"].layer = 2;
Animationen["Walk_Weapon"].AddMixingTransform(RightLeg, true); Animationen["Walk_Weapon"].AddMixingTransform(LeftLeg, true);
}
// Update is called once per frame
void Update () {
//Walk
if (Input.GetAxis("Vertical") > 0.2)
{
Animationen["Walk_Weapon"].speed = 1.5F;
Animationen.CrossFade("Walk_Weapon");
}
//Idel
if (Input.GetAxis("Vertical") == 0 && Input.GetAxis("Horizontal")==0)
{
if (IsWeaponMode())
Animationen.CrossFade("Idle_Weapon");
else
Animationen.CrossFade("Idle");
}
}
Answer by Cyb3rManiak · May 05, 2011 at 10:58 AM
In the scripting reference, CrossFade is defined as:
function CrossFade (animation : string, fadeLength : float = 0.3F, mode : PlayMode = PlayMode.StopSameLayer) : void
I might be way off, but notice the PlayMode.StopSameLayer. The default behaviour is to stop all the rest of the animations in the same layer, and the other option is to stop the animation on all layers... So either make "Idle" and "Walk_Weapon" on different layers (this might cause you problems if you want to sync them later on), or try and use Animation.Blend instead.
I'm sorry - I don't have time right now to test your code out. I'll try and check in later if you still have a problem...
But if Walk has "Loop" as wrap$$anonymous$$ode, the walking won't stop if I want to fade back to "Idle". What can I do in that case? An additive blendmode just plays the half of an animation and that really slow :/
The walk animation WILL stop if you blend it to a weight of 0. It might be somehow running in the background (calculating what keyframe is next etc.), but if it has a weight of 0.0 - it will have no effect on anything. You can also stop it in that case, and start it again the next time you need it using Crossfade() or QueuedCrossFade(). Also - if you WANT it to stop - just CrossFade like you did in the code you posted.
Have you tried separating the two animations to different layers? Do you have some reason they are in the same layer in the first place?