- Home /
Help with blending animations
I'm sure it could be a simple problem but I'm having trouble with blending my animations in my models together. I've got some models with animations which my artist gave me from maya, and I've set up the different cycles in the inspector.
What happens though is when I want to change the animation of the object, the animation doesn't finish its cycle properly (e.g. the arms and legs are out of position when going from the walk to idle animation).
I'm declaring the animations in the Start() function as below.
function Start() { if(target == null && GameObject.FindWithTag("Player")) { target = GameObject.FindWithTag("Player").transform; }
animation.wrapMode = WrapMode.Loop; animation.Play("Idle"); animation["Walk"].wrapMode = WrapMode.Loop;
}
And declaring them as below
function ChasePlayer() { //print ("Chasing Player"); animation.CrossFade("Walk"); dir = target.transform.position - transform.position;
dir = dir.normalized; transform.Translate(dir speed 5 * Time.deltaTime, Space.World); }
Basically what happens exactly is when there is a call to switch animation, the body parts that need to move for the new animation become animated, but the parts that are not animated become frozen in the position they were at when the animation gets changed. Anyone know where the problem is?
Hi, may I ask what's the format of the animated models (e.g. fbx or mb)?
Answer by MaDDoX · Jul 22, 2010 at 03:54 PM
That's what happens when you use 'crossfade', the animation(s) that is(are) currently playing blend its weight to zero (fade out) while the new animation blends its weight to one (fade in) along the duration of the crossfade, in practice completely replacing the original animation at the end of the transition.
What you probably want is to playback the idle animation in a higher layer, just set the animation["Walk"].layer = 1 before issuing a play/blend command. Also bear in mind that, in this case, if the idle animation has keyframes set for the legs, they will affect the walk animation, which is probably not what you want. I recommend you bake your animation in your 3D app, deleting the unneeded/conflicting keyframes and, after import, disable unity's own bake in the asset inspector properties.
Good luck!
"() if the idle animation has keyframes set for the legs, they will affect the walk animation, which is probably not what you want. I recommend you bake your animation in your 3D app, deleting the unneeded/conflicting keyframes ()" --
Can we use Animation blending.Additive or something similar, to combine animations in different layers, regardless of whether they has keyframes in common bones?
I've tried that with quite undesirable results. The simple fact is that any kind of animation blend that changes the position of the feet will lead to "sliding feet", even if you've already properly set the animation speed to match the character's in-game speed.
One alternative that I'm using is use the free 'locomotion system' (which you can find in the Unity's website) to automatically plant the feet of the character regardless of any other animations going on. Just be aware that Locomotion does have some restrictions to work, try with its own character in your project first. Good luck!
Your answer
Follow this Question
Related Questions
Can I make animations snap to a frame? 1 Answer
Maya animation import 0 Answers
Animations not appearing in the inspector. 1 Answer
Can Unity support Maya set driven keys? 1 Answer
Maya animation problem in unity 1 Answer