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 puelo · Jan 01, 2012 at 08:35 PM · animationcharacteranimationstate

CrossFade/Blend Additive Animations?

Hey there,

i have an character with some animations. They are mostly divided into two parts, like:

RunBase and RunTop

IdleBase and IdleTop

Its mainly for the purpose of changing the arm animation while running. Now my problem: I want to blend or fade the animations into another. Here is my Code so far:

  public Transform shoulder;
     AnimationState RunTop;
     AnimationState IdleTop;
     
     void Start() {
         animation.Stop();
 
         animation.wrapMode = WrapMode.Loop;
 
 
         RunTop = animation["RunTop"];
         RunTop.weight = 1.0f;
         RunTop.wrapMode = WrapMode.Loop;
         RunTop.layer = 11;
         RunTop.blendMode = AnimationBlendMode.Blend;
         RunTop.AddMixingTransform(shoulder);
 
         IdleTop = animation["IdleTop"];
         IdleTop.weight = 1.0f;
         IdleTop.wrapMode = WrapMode.Loop;
         IdleTop.layer = 10;
         IdleTop.blendMode = AnimationBlendMode.Blend;
         IdleTop.AddMixingTransform(shoulder);
     }
 
 
     void Update () {
         PlatformerControllerSinbad controller = GetComponent("PlatformerControllerSinbad") as PlatformerControllerSinbad;
 
         if (controller.IsMoving())
         {
             animation.CrossFade("RunBase");
             RunTop.enabled = true;
         }
         else
         {
             
             animation.CrossFade("IdleBase", 0.5f);
             RunTop.enabled = false;
             IdleTop.enabled = true;
         } 
     }

The Transform Object "shoulder" is the upper Part of the Body. Hope some1 can help me. Im grateful for any tip!

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

5 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Owen-Reynolds · Jan 02, 2012 at 02:41 AM

Crossfade is made to smooth from one to the other. The same way you are using it for the base, use it for the top. You'll need to have them on the same layer (instead of 10 and 11.)

CrossFade("A") automatically ramps up A, and ramps down the weight of whatever was on the same layer as A.

EDIT: (on response to questions entered as answers)

If you read the animation docs, the default settings are fine. So, you don't have to set weight=1, speed=1, blendMode=blend... . All you need to set is the layer, if not 0. A lot of examples uselessly to set these, to show where you would be able to change speed to 50%, say.

CrossFade by itself really is made to solve the most common situation. Enable is for special circumstances (like you are going into a ragdoll.) The Ex from the docs really does work:

// these three animations are on the same level, and looping:
if(shooting) animation.CrossFade("upperGunAim");
else if(running) animation.CrossFade("upperArmPump");
else animation.CrossFade("upperIdle");
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
avatar image
0

Answer by puelo · Jan 02, 2012 at 02:55 PM

But im just enabling the AnimationState for the upper Part (IdleTop.enabled = true). How im a able to Crossfade those?

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
avatar image
0

Answer by puelo · Jan 02, 2012 at 02:55 PM

And another question. Do i have to set the options for the AnimationState for every UpperBody Animation?

  RunTop = animation["RunTop"];
     RunTop.weight = 1.0f;
     RunTop.wrapMode = WrapMode.Loop;
     RunTop.layer = 11;
     RunTop.blendMode = AnimationBlendMode.Blend;
     RunTop.AddMixingTransform(shoulder);

     IdleTop = animation["IdleTop"];
     IdleTop.weight = 1.0f;
     IdleTop.wrapMode = WrapMode.Loop;
     IdleTop.layer = 10;
     IdleTop.blendMode = AnimationBlendMode.Blend;
     IdleTop.AddMixingTransform(shoulder);


Or is there an easier and maybe better way to do this? Because i will have 3 more seperate Animations.

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
avatar image
0

Answer by puelo · Jan 02, 2012 at 07:40 PM

So by setting things up like:

 RunTop = animation["RunTop"];
 RunTop.AddMixingTransform(shoulder);

It also affects the animation.Crossfade (so that animation.CrossFade("RunTop") is just a CrossFade for the upper Body part?). And by setting up different Layers for the "Top" Animations i can seperately control the weights in the upper and lower body half?

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
avatar image
0

Answer by puelo · Jan 03, 2012 at 12:16 AM

Alright...i guess i got it working with your help. This is my Script:

 public Transform shoulder;
 AnimationState RunTop;
 AnimationState IdleTop;
 AnimationState DrawSwords;
 AnimationState HandsClosed;
 void Start() {
     animation.Stop();

     animation.wrapMode = WrapMode.Loop;

     HandsClosed = animation["HandsClosed"];
     HandsClosed.weight = 1.0f;
     HandsClosed.layer = 1;
     HandsClosed.wrapMode = WrapMode.ClampForever;
     HandsClosed.blendMode = AnimationBlendMode.Blend;
     HandsClosed.AddMixingTransform(shoulder);

     DrawSwords = animation["DrawSwords"];
     DrawSwords.weight = 1.0f;
     DrawSwords.layer = 2;
     DrawSwords.wrapMode = WrapMode.Once;
     DrawSwords.blendMode = AnimationBlendMode.Blend;
     DrawSwords.AddMixingTransform(shoulder);

     RunTop = animation["RunTop"];
     RunTop.weight = 1.0f;
     RunTop.layer = 1;
     RunTop.wrapMode = WrapMode.Loop;
     RunTop.blendMode = AnimationBlendMode.Blend;
     RunTop.AddMixingTransform(shoulder);

     IdleTop = animation["IdleTop"];
     IdleTop.weight = 1.0f;
     IdleTop.layer = 1;
     IdleTop.wrapMode = WrapMode.Loop;
     IdleTop.blendMode = AnimationBlendMode.Blend;
     IdleTop.AddMixingTransform(shoulder);




     int jumpingLayer = 3;
     AnimationState jump = animation["JumpStart"];
     jump.layer = jumpingLayer;
     jump.wrapMode = WrapMode.Once;

     AnimationState jumpFall = animation["JumpLoop"];
     jumpFall.layer = jumpingLayer;
     jumpFall.wrapMode = WrapMode.ClampForever;

     AnimationState jumpLand = animation["JumpEnd"];
     jumpLand.layer = jumpingLayer;
     jumpLand.wrapMode = WrapMode.Once;

 }


 void Update () {
     PlatformerControllerSinbad controller = GetComponent("PlatformerControllerSinbad") as PlatformerControllerSinbad;

     if (controller.IsMoving())
     {
         animation.CrossFade("RunBase");
         //RunTop.enabled = true;
         animation.CrossFade("RunTop");
     }
     else
     {
         
         animation.CrossFade("IdleBase", 0.5f);
         //RunTop.enabled = false;
         animation.CrossFade("IdleTop", 0.8f);
     }

     if (Input.GetKeyDown("e"))
     {     
         animation.CrossFade("DrawSwords");
     }
 }

 void DidJump()
 {
     animation.Play("JumpStart");
     animation.PlayQueued("JumpLoop");
 }

 void DidLand()
 {
     animation.Stop("JumpLoop");
     animation.Play("JumpEnd");
     animation.Blend("JumpEnd", 0);
 }

 void DidDraw()
 {
     HandsClosed.enabled = !HandsClosed.enabled;
 }

I have set the UpperBody Animations on Layer 1 and the Run / Idle Animation on Layer 0. Is this how it should be done? (except the blendMode / weight settings)..

Because now i got another odd problem. The "DrawSwords" Animation is getting played when i press "e" - but only Once in the whole "GameSession. So if i press "e" again it seems like it is just playing the first frame of the animation. Is there something wrong with my settings? The Animation works fine, ive already tried it in Loop Mode.

Thanks for all the help so far!

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

AnimationState.AddMixingTransform 1 Answer

is it possible to rig and animate withing unity? 1 Answer

character & objects import in different scale & animation dosent work right anymor!!!! 1 Answer

Increase jump height/distance 0 Answers

Character Animation Wont Play 2 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