Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Nercoe · Oct 16, 2012 at 09:26 PM · animationtimedoublesame

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 :/

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Mrobertson · Oct 16, 2012 at 10:38 PM

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);
Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Nercoe · Oct 16, 2012 at 10:43 PM 0
Share

Thanks buddy, would the wave hand be the swordwing animation and what would replace "shoulder"?

avatar image Michael Covert · Oct 16, 2012 at 10:58 PM 0
Share

Shoulder here would be the transform of the highest bone in the hierarchy that you want the animation to affect - most likely whatever bone you have as your character's shoulder.

wave_hand would be your swordswing animation, yeah.

avatar image Nercoe · Oct 16, 2012 at 11:00 PM 0
Share

Thanks mate I'll give it a try now :) Fingers crossed!

avatar image Nercoe · Oct 16, 2012 at 11:08 PM 0
Share

Alright, we have progress! It's now working for my A key (when I walk the other way ^^ ) I will hammer it a bit more try and iron out the bug, either way, I'll be back to rep you both :)

avatar image Nercoe · Oct 16, 2012 at 11:11 PM 0
Share

Brilliant got it working! Thank you very much! I'm unsure if I can mark 2 answers as correct on Unity but if I can, post yours as an answer as well. Both played a part in fixing this. Seriously I cannot tell you how grateful I am :D I thought this would be the downfall of me lol :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Playing 2 animations at the same time 2 Answers

How do I play muiltiple animations? 1 Answer

How can I read time from clip that is PlayQueued? 1 Answer

two projects in the same time 4 Answers

Animation.Time help 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges