Animation blending. (two animations, same mesh, same time)

Hey, this one has really got me going! I’ve been on here for a little over a month now and you guys have taught me so much but I’m having a little trouble blending my animations together. Here’s what I want to accomplish:

When the D key is pressed, my character walks with the “walk” animation. Everything is fine here. My character has a sword, the sword animation is named “swordswing”. Both animations play fine, I have double checked this. What I want is when the character is walking, if the key “P” is pressed, the animation “swordswing” plays over the top of the walking animation (but I want the legs to still move). At the moment the animation plays seperatley (stops the walking) and initiates the swordswing.

At the moment, the animation cancels the other one out, the swordswing animation has no keyframe movement on the legs so shouldn’t the animation carry on? Have I done this correctly?

I want my character to swing the sword but his legs continue to move as he does so. I know this is done by blending but I can’t see where I have gone wrong, any help will be hugely appreciated!

Sorry for the messy code! I have not formatted it yet.

var acceleration : float = 100;
var move : float;
var doubleJump : float = 0;
var z : float;
var left : Transform;
var right : Transform;
var health : int = 100;
var jumpDelay : boolean = false;

function Start () {

jumpDelay = false;
   animation.wrapMode = WrapMode.Loop;
   animation["jump"].wrapMode = WrapMode.Once;
   animation["swordswing"].wrapMode = WrapMode.Once;
   animation["jump"].layer = 1;
   animation["swordswing"].layer = 1;
   animation["swordswing"].weight=0.4f;
      



   animation.Stop();
}



function Update () {

//Movement without guns goes here

     		Physics.gravity = Vector3( 0, -200, 0);
        	animation.CrossFadeQueued("random");
        	

        	
     
             if( Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.D))
        {
        		acceleration = 100;

    			animation.Play("walk");
 	
    	}
    	
    	    	        	        else if( Input.GetKeyDown(KeyCode.P))
        {
		animation.Blend("swordswing");
    			}
    	

    	
    	else if( Input.GetKeyDown(KeyCode.Space) && jumpDelay == false )
   				 {
     				Jump();
          				animation.CrossFade("jump");
          				animation.CrossFadeQueued("idle");   
          			jumpTimer();
	          	    		          	
  				 }

		else if (Input.GetKeyUp(KeyCode.D) || Input.GetKeyUp(KeyCode.A))
				{
		animation.CrossFade("idle"); 
	
				}

		
		//Stop the moonwalking bug
		if (Input.GetKey(KeyCode.D) && Input.GetKey(KeyCode.A))
	{
		acceleration = 0;
		animation.CrossFade("idle");
	}
		else if (Input.GetKey(KeyCode.D))
			{
		acceleration = 100;
		animation.CrossFade("walk");
		
			}
		if (health == 0){
		
			animation.Play("death");
			animation.wrapMode = WrapMode.Once;
			health = 100;
			}
    	
    	
         move = Input.GetAxis("Horizontal") * acceleration * Time.deltaTime; 
     	transform.Translate (0, 0, move); 
}

function Jump(){


	    doubleJump +=1;

    if( doubleJump == 1 )
    {
       rigidbody.velocity.y = 175;
    }

}

function OnCollisionStay (collision : Collision){
		doubleJump = 0;
}
function OnCollisionExit (collision : Collision){
     	doubleJump = 1;

}

function jumpTimer(){
	if (animation.IsPlaying("jump"))
	jumpDelay = true;
		yield WaitForSeconds(3);
	jumpDelay = false;
	}

I will be here for a while so feel free to ask for any additional information.

Summary: I want the sword animation to play at the same time as the walking animation, without stopping my characters legs from moving. I really need this fixing and any guidance will be greatly appreciated. Thank you.

Additional information:

Sword animation : swordswing
Walking animation: walk

Please note: I have read a lot of documentation on this but unfortunately, I cannot take anything from it for my script :confused:

It sounds like you will have to use AnimationState.AddMixingTransform to have your sword swing animation only affect the upper body joints

From the Documentation

/// Adds a mixing transform
var shoulder : Transform;
animation["wave_hand"].AddMixingTransform(shoulder);