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 AngryCSharpNerd · Dec 07, 2012 at 01:32 AM · animationcrossfadeblend

Animation blending/crossfading sword help

 #pragma strict
 var swordSpeed = 0.5;
 var slash: AudioClip[];
 private var t:float;
 var head:CharacterController;
 
 function Start(){SwordBobble();}
 
 function SwordBobble(){
     var sword = gameObject.Find("blade");
     var ani = sword.animation;
     while(true){
         if(head.isGrounded  && head.velocity.magnitude >= 4){ //&& !animation.animations.swordslash.isPlaying){
             ani["SwordBobble"].speed = 1;
             ani.Play("SwordBobble");
             //ani.CrossFade("SwordBobble");            
             yield WaitForSeconds(0.001);
         }
         else{
             ani["SwordBobble"].speed = 0;
             //animation.Stop();
             yield;
         }
     }
 }
 
 function Update(){
     if(GameObject.Find("Gameover") == null){Disable();}
     t += Time.deltaTime;
     if(t >= 0.5 && GameObject.Find("Enabled") == null && GameObject.Find("blade") != null && GameObject.Find("Gameover") != null && GameObject.Find("PauseNo")!= null && GameObject.Find("GUI_black").guiTexture.color.a <= 0){
         if(Input.GetButtonDown("Fire1")){
             var sword = gameObject.Find("blade");
              if(sword != null && GameObject.Find("SlashFalse") != null){
                  //var ani = sword.animation;
                  var anistate = sword.animation["swordslash"];
                      sword.animation.Play("swordslash");
                      audio.pitch = Random.Range(1.0 - 0.05, 1.0 + 0.05);
                      var ran = slash[Random.Range(0,slash.Length)];
                      audio.clip = ran;
                      audio.Play();
                          t = 0;
             }
         }
     }    
 }

I've been having a bit of trouble lately. As you can see, I have two main functions of this script: one triggers a SwordBobble, like where the sword bounces around while walking, and the second function is to trigger a sword slashing animation, which plays when triggered by Fire1.

My big problem is that while I am walking, the SwordBobble animation is playing, so when I try to play a sword slash animation, it's being overlapped by SwordBobble.

I don't know the difference between crossfade and blending exactly - is blending to literally mix in two or more animations and crossfade just "fades" out an animation? What would that look like? I'm confused on what they do.

So, my goal here is to make it so SwordSlash will, I guess "blend" in with SwordBobble, and then play the swordslash animation, and then once the swordslash animation is finished, it will automatically go back/blend back to SwordBobble mode.

Swordslash only plays when I am not moving, and I need it so it can play while moving as SwordBobble is playing also.

I don't know how I can set up these blending and crossfading functions, so may someone help me on how I can accomplish this? Please do not speak with a lot of elitism, as I usually can't follow what you're saying. Thank you very much for taking the time to read my frustration.

Comment
Add comment · Show 1
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 AngryCSharpNerd · Dec 07, 2012 at 09:35 PM 0
Share

Help... :(

2 Replies

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

Answer by MibZ · Dec 07, 2012 at 10:01 PM

I haven't done that much work with animation blending but I have read a lot about it in anticipation of a future project. The layer value of an animation determines how important it is, if you set the layer value of your idle animations to -1, any animation with a layer higher than it should be given a higher priority and fade over the idle.

I'm not 100% sure as I haven't done it before, but I distinctly remember reading that and it is a very quick thing to try, hate to see somebody ask a question and get no responses at all, so I figure this is more valuable than nothing.

Comment
Add comment · Show 4 · 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 AngryCSharpNerd · Dec 07, 2012 at 10:18 PM 0
Share

Oh. Even though you haven't done much with animation, can you explain to me what animation crossfade and blending does? I'm trying to get them to work but it seems that I just don't know how to use them because I don't exactly know what they do.

avatar image MibZ · Dec 07, 2012 at 10:25 PM 0
Share

From my understanding blending is used to move towards a specific part of the animation over time without effecting other animations and crossfading is used to make a smooth transition from one animation to another (effecting both animations) ins$$anonymous$$d of immediately stopping animation A and starting animation B.

avatar image AngryCSharpNerd · Dec 07, 2012 at 10:45 PM 0
Share

Okay, so I probably need to use CrossFade in order to transition from the swordbobbling to the swordslashing, and vice versa.

I can't seem to get this working.

avatar image AngryCSharpNerd · Dec 07, 2012 at 11:03 PM 0
Share

Never$$anonymous$$d, I finally got the whole thing working. I unfortunately found out I had another script enabled that screwed around with my script.

avatar image
0

Answer by Dyon09 · Dec 09, 2012 at 12:58 AM

I tried using a variation of this script for a project that I have, but Unity classifies 'Disable' as an "Unknown Identifier"

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 AngryCSharpNerd · Dec 09, 2012 at 01:49 AM 0
Share

Yeah sorry, I removed my function Disable(){ thing because it was entirely unrelated to the help I needed.

avatar image AngryCSharpNerd · Dec 09, 2012 at 01:51 AM 0
Share

The disable line isn't needed.

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

what is difference of animation blend and animation crossfade? 0 Answers

Animation.Play blends previous animation 1 Answer

How to play multiple animations on the same game object. 2 Answers

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

Animation Stop and Stay 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