- Home /
Combining two animations?
So basically, is there a way to blend two animations? I have a sword attack animation, and I have a walk animation. The sword attack animation works when idle, and then the walk obviously works while he's walking.
But how can I combine it so the sword attack works while he's walking too? Like so his upper body still attacks like the sword attack, but then his lower body (legs/hips) still work like the walk animation?
Any ideas?
thanks
Answer by jerobinson · Jun 08, 2013 at 03:41 PM
To achieve the result you want, you need to add a mixing transform. So basically, how this works is you define an armature in the characters body, and then every child of that armature will play one animation, while the rest play a different.
For Example:
using UnityEngine;
using System.Collections;
public class AnimationExample : MonoBehaviour {
public Transform upperBody; // This should be the bone from which all children will play attack animation
void Start() {
animation["SwordAttack"].AddMixingTransform(upperBody); // Adds a mixing transform using the bone transform defined above
}
void Update() {
animation.Play("RunAnimation");
animation.Play("SwordAttack");
}
}
To use this example, you would find the relevant armature in your character, then drag it onto the "upperBody" variable (or whatever).
Hope this helps ;)
Ahh ok that makes sense! Thanks! But would this not alter the sword attack animation while it's standing still though?
Yes it would. $$anonymous$$aybe if you try adding the mixing transform only when the player is moving?
Try looking at this link: http://docs.unity3d.com/Documentation/ScriptReference/AnimationState.Add$$anonymous$$ixingTransform.html It helped me a lot and it is very clear. I would give jerobinson's answer the best because he is correct. Hope this helps :)
How do I do this if my object has an Animator ins$$anonymous$$d of an Animation?
Answer by Mukabr · Jun 10, 2013 at 04:28 AM
http://docs.unity3d.com/Documentation/ScriptReference/Animation.CrossFade.html
animation.CrossFade is what you need.
Crossfade will only blend between animations, but it wont allow two to play at one time.... hmmmm