• 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 ShadowBroker · May 05, 2011 at 10:45 AM · animationlayercrossfade

Play an animation just on some parts of the body

I know that I can use layers to set animation prirority and AddMixingTransform to just set animate some parts of a mesh. Unfortunately, it doesn't really work. Everytime I want to crossfade to the walkanimation(that just animates the legs) it also fades the idle animation out but it should keep playing "Idle" and should just overwrite the animation of the legs. What is wrong with the script? I can't find something I miss there

void Start () {

Animationen["Idle"].layer = 2; Animationen["Walk_Weapon"].layer = 2;

Animationen["Walk_Weapon"].AddMixingTransform(RightLeg, true); Animationen["Walk_Weapon"].AddMixingTransform(LeftLeg, true);

}

// Update is called once per frame

void Update () {

     //Walk
     if (Input.GetAxis("Vertical") > 0.2)
     {
         Animationen["Walk_Weapon"].speed = 1.5F;
         Animationen.CrossFade("Walk_Weapon");
     }

     //Idel
     if (Input.GetAxis("Vertical") == 0 && Input.GetAxis("Horizontal")==0)
     {
         if (IsWeaponMode())
             Animationen.CrossFade("Idle_Weapon");
         else
             Animationen.CrossFade("Idle");
     }

}

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
1

Answer by Cyb3rManiak · May 05, 2011 at 10:58 AM

In the scripting reference, CrossFade is defined as:

function CrossFade (animation : string, fadeLength : float = 0.3F, mode : PlayMode = PlayMode.StopSameLayer) : void

I might be way off, but notice the PlayMode.StopSameLayer. The default behaviour is to stop all the rest of the animations in the same layer, and the other option is to stop the animation on all layers... So either make "Idle" and "Walk_Weapon" on different layers (this might cause you problems if you want to sync them later on), or try and use Animation.Blend instead.

I'm sorry - I don't have time right now to test your code out. I'll try and check in later if you still have a problem...

Comment
Add comment · Show 2 · 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 ShadowBroker · May 05, 2011 at 11:39 AM 0
Share

But if Walk has "Loop" as wrap$$anonymous$$ode, the walking won't stop if I want to fade back to "Idle". What can I do in that case? An additive blendmode just plays the half of an animation and that really slow :/

avatar image Cyb3rManiak · May 05, 2011 at 04:31 PM 0
Share

The walk animation WILL stop if you blend it to a weight of 0. It might be somehow running in the background (calculating what keyframe is next etc.), but if it has a weight of 0.0 - it will have no effect on anything. You can also stop it in that case, and start it again the next time you need it using Crossfade() or QueuedCrossFade(). Also - if you WANT it to stop - just CrossFade like you did in the code you posted.

Have you tried separating the two animations to different layers? Do you have some reason they are in the same layer in the first place?

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Animation: Impact of combining the use of Layer, CrossFade, and Weight 2 Answers

How can I smoothly transition my player camera from manual control into an animation? 1 Answer

Animation plays without a bool, but after adding it just goes still 0 Answers

Animator.CrossFade or Animator.CrossFadeInInFixedTime does not play animation after crossfading. 0 Answers

Animator with mask problem 0 Answers


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