How to combine animations ?

Hello everyone !

I’m new at unity, but I already love it and intend to develop several things on it !

After a lot of tutorials on the internet, answers found in this forum (thanks for this huge community by the way :slight_smile: ), I found myself in front of a big problem without finding any solutions : combining animations.

I started a multiplayer FPS.
My character has several animations (walk, idle, jump, knife shot, …). My problem is I want the character to walk when the up arrow is pressed (no problem for that), arms to move for a knife shot when fire1 is pressed (no problem again), BUT, the combination of the two of them il a problem. I tried several solutions, but nothing worked as i wanted :frowning:

The problem is that my walk animation is looking good when i hit with the knife, but the knife shot animation is like “limited”, the arm moves not as high as it should go, not as high as it goes if the character is not walking in the mean while…
There is also a little glitch on the walk animation while the knife animation is playing but i think this is the same problem. There is some knid of interaction between the 2 animations.

At first the walk animation moved shoulders and feet and the knife animation was moving only shoulders. Then I removed the shoulders animation in the walk to not have interferences but it changes nothing. I’m sure it’s an obvious solution and i’m missing something huge but I can’t figure it out myself. Any suggestions ? Thanks for advance :slight_smile:

This is the code (with only important ligns):

function Start () {
	animation["knife"].layer=1;
	animation["knife"].blendMode = AnimationBlendMode.Blend;
	animation["walk"].blendMode = AnimationBlendMode.Blend;
}

function Update() {
    	if (Input.GetButtonDown("Fire1"))
    	{
    		Fire();
    	}
    	
    	if (Input.GetKeyDown(KeyCode.UpArrow))
    	{
    		if (!animation.IsPlaying("walk"))
    		{
    			animation.CrossFade("walk");
    		}
    	}
    }
    
function Fire() {
    animation.CrossFade("knife");
}

Look into AddMixingTransform function - it allows you to play one animation on lowerbody and other on upperbody.

Welcome to Unity Answers!