Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 ytniu · Aug 24, 2011 at 11:10 AM · c#animationblending

How to add two animations?

Hi, I have an avatar controller which handles some animations (walk, idle, jump, salute).

I want to salute while I'm idle or walking so the way I'm doing it is:

 public Transform mixBone;


 animations[walk.name].layer = -1;
 animations[idle.name].layer = -2;
 animations.SyncLayer(-1);
 animations[walk.name].normalizedSpeed = 1;    
         
 
 animations[jump.name].layer = 5;
 animations[jump.name].wrapMode = WrapMode.ClampForever;
 animations.SyncLayer(5);
 animations[salute.name].layer = 5;    
 animations[salute.name].wrapMode = WrapMode.Once;
 animations[salute.name].blendMode = AnimationBlendMode.Blend;
 animations[salute.name].AddMixingTransform(mixBone);


And then this is my update():

 if(!motor.IsMoving())
 {
     animations.Blend(walk.name, 0.0f, 0.3f);
     animations.CrossFade(idle.name);
         }
         else
             animations.CrossFade(walk.name,0.3f);
         }
 }



And....

 void DidSalute() 
 {
        animations.Blend(salute.name,1);
 }

Which is called when an input key is pressed.

I don't know why... but it seems that salute is executed but it's overrided by the walk/idle animation and the salute animation doesn't finish.

Maybe because of the Update() crossfade¿?

EDIT:

It works with BlendMode.Blend.

http://unity3d.com/support/documentation/Manual/Character-Animation.html

http://unity3d.com/support/documentation/ScriptReference/Animation.html

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

2 Replies

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

Answer by Owen-Reynolds · Aug 24, 2011 at 09:22 PM

Two problems. One is your salute is probably short enough that the fade in/out overwhelms it. Blend with a weight of 1.0 works the same as Crossfade. It fades in, then out (for a PlayOnce,) with a default fade in/out time of 0.3 seconds, at each end. For a looping walk, that's fine. For a 1 second salute, that leaves only the middle 4/10ths playing normally. In other words, at 70% of the way there, it says "time to start heading back."

Try shortening the fade-in time: CrossFade("salute" , 0.05f); or Blend("salute",1 , 0.05f); 0.05 doesn't seem like much, but at 60fps, it's 3 frames.

The other problem is what the previous answer refers to. You have salute set as an "ADD" animation. Adds play on top on other animations. Salute played as normal (blend) says to put your hand in an exact spot, overriding other animations. Played as an add, it says to twist your arm 180 degrees from where-ever it is and bend your hand an extra 90 degrees. That will gladly put your hand behind your back, as you arm continues to "walk pump."

ADD is one way to solve the problem of "how do I combine idle and salute?" For a shiver, say, it's perfect. For the salute, you probably want only the arm to salute anyway, while the rest of the bones play idle/walk. Leave salute as normal (blend) (but it won't blend since weight is 1,) keep it on a higher layer, but limit the bones:

 // drag rightArmbone into Inspector on this:
 public Transform rightArmBone;

 // or, don't drag and in Start:
 rightArmBone = transform.Find("bones/chest/Rshoulder/RupperArm") as Transform;

 // either way:
 animation["salute"].AddMixingTransform(rightArmbone);
 // playing salute now animates only upperArm and its children,
 // lets lower level animation (idle/walk) control other bones

Also, SynchLayer is used to force multiple animations on one layer to have the same times (if you have a 1 and 2 second animation on layer 4, SynchLayer(4) sets them both to 1.5 secs.) I think it's a bit of a red herring in your code -- you only call it when a layer has one animation, and I doubt you want jump and salute to synch up. It's useful for averaging animations, which is the 3rd way of playing two at once.

Comment
Add comment · Show 1 · 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 ytniu · Aug 25, 2011 at 10:04 AM 0
Share

I edited my answer with more info... thanks :)

avatar image
0

Answer by roamcel · Aug 24, 2011 at 03:31 PM

What you need is a specific approach which is somewhat difficult to explain and understand, but which is exactly what you need.

link text

It basically allows one animation to affect only a subtree of the armature. In this case for example, if the salute is performed with the right arm, you should apply it to the right shoulder.

Comment
Add comment · 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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Character Controller 1 Answer

What is the best way to return a deformed mesh to its initial shape? 1 Answer

Unsure of how to make a certain animation play 1 Answer

Stop clips from an Animations array on an Animation component 0 Answers

Attack animation Wont Play 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