I have my animations separated into lower body animations (idle, walk, run) and upper body animations (point, wave, etc). I'd like to be able to have the character wave (using his upper body) while his lower body is either idle, walking, running, etc.
I've looked into Unity's manual's example but I don't understand everything and unfortunately I'm unable to get it to work.
AddMixing Animation example
Unity Doc's on Additive Animation
Does anyone have any experience with this? Essentially I'd like to do this:
// run and wave
animation.Play("UB_wave"); // play upper body animation
animation.Play(“LB_run”); // play lower body animation
...
// uh oh there's an alien
animation.Play("UB_point"); // play upper body animation
animation.Play("LB_idle"); // play lower body animation
I haven't used this, but Animation.AddMixingTransform is used mostly to do that. It plays an animation from a bone down. So if you are playing a walk animation in the legs, you can play a different animation from the waist up.
Edit. Ok, so I spent some time playing with Mixing Animations and I got it working. Here's an example to see how it works basically.
using UnityEngine;
using System.Collections;
public class MixingDemostration : MonoBehaviour {
public Transform shoulder;
public bool isEnabled;
AnimationState mixAnimation;
void Start() {
animation["walk"].wrapMode = WrapMode.Loop;
mixAnimation = animation["punch"];
mixAnimation.weight = 1.0f;
mixAnimation.wrapMode = WrapMode.ClampForever;
mixAnimation.layer = 10;
mixAnimation.blendMode = AnimationBlendMode.Blend;
mixAnimation.AddMixingTransform(shoulder);
mixAnimation.enabled = isEnabled;
//enabled seems to control the whole thing.
//or I would guess you can call CrossFade or Play or Blend
}
void Update () {
if(Input.GetButtonDown("Jump")) {
mixAnimation.enabled = !mixAnimation.enabled;
}
}
}
changing this code
mixAnimation.enabled = !mixAnimation.enabled;
by
animation.CrossFade(mixAnimation.name);
this works well for me