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 Zikku · Feb 20, 2012 at 03:24 AM · javascriptswitchstatesanimation-blending

Scripting-Animation Issue

In the prototype I'm working on, I have it so the space bar makes the character jump and the Fire1 button makes the character perform a random attack (out of the two I have animated). The movement controls are the typical W,A,S,D setup and the Fire2 button can orbit the camera around your character.

I've gotten the crossfades to work nicely while holding down the appropriate keys to move the character forward, backward, pivot left, and pivot right (I haven't restricted them to stop the pivot animations from playing while running and turning just yet, but that will be for later. I also have two attack animations, and a temporary jump animation. I'm still messing with the jump animation for it's timing at the appropriate parts of the jump, so for the time being, it's just supposed to play the whole thing at the standard frame-rate.

The issue is that while the W,A,S,D buttons require to be held down to loop through their animations and crossfade back to idle while they're not being held down, the space bar and Fire1 are supposed to just continue playing after the click or touch, but they don't. Regardless if I use GetButtonDown or GetButton, I get the same result. Any suggestions?

 for (var i: KeyCode in zikkuKeys)
     {
         if(Input.GetKey(i))
         {
             switch(i)
             {
                 case KeyCode.W:
                     PerformSomething(ZikkuState.Running);
                 break;
                 case KeyCode.A:
                     PerformSomething(ZikkuState.PivotLeft);
                 break;
                 case KeyCode.S:
                     PerformSomething(ZikkuState.MoveBackwards);
                 break;
                 case KeyCode.D:
                     PerformSomething(ZikkuState.PivotRight);
                 break;
                 case KeyCode.Space:
                     if(canJump == true)
                     {
                         PerformSomething(ZikkuState.Jumping);
                     }
                 break;
             }
         }
         if(Input.GetButtonDown("Fire1"))
         {
             PerformSomething(ZikkuState.Attacking);
         }
         else if(!Input.anyKey)
         {
             PerformSomething(ZikkuState.Idle);
         }

And here's the function Perform Something that explains what each acceptable input does.

 function PerformSomething(currentState : ZikkuState)
 {
     movePlayer = (Vector3.forward*Time.deltaTime);
     turnPlayer = (Vector3.up*Time.deltaTime);
     
     switch(currentState)
     {
         case ZikkuState.Idle:
             zikkuChar.animation.CrossFade("idle", 0.2);
         break;
         case ZikkuState.Running:
             transform.Translate(movePlayer * runSpeed);
             zikkuChar.animation.CrossFade("run", 0.2);
             zikkuChar.animation.wrapMode = WrapMode.Loop;
         break;
         case ZikkuState.MoveBackwards:
             transform.Translate(-movePlayer * moveBackSpeed);
             zikkuChar.animation.CrossFade("moveBackward", 0.2);
             zikkuChar.animation.wrapMode = WrapMode.Loop;
         break;
         case ZikkuState.PivotLeft:
             transform.Rotate(-turnPlayer * turnSpeed);
             zikkuChar.animation.CrossFade("pivotLeft", 0.2);
             zikkuChar.animation.wrapMode = WrapMode.Loop;    
         break;
         case ZikkuState.PivotRight:
             transform.Rotate(turnPlayer * turnSpeed);
             zikkuChar.animation.CrossFade("pivotRight", 0.2);
             zikkuChar.animation.wrapMode = WrapMode.Loop;
         break;
         case ZikkuState.Jumping:
             lastJumpButtonTime = Time.time;
             zikkuChar.animation.CrossFade("JumpTemp", 0.2);
             zikkuChar.animation.wrapMode = WrapMode.Once;
             print("Zikku jumped.");
         break;
         case ZikkuState.Attacking:
             ZikkuAttacks();
         break;
         default:
             zikkuChar.animation.CrossFade("idle", 0.2);
         break;
     }
 }
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 Zikku · Sep 25, 2012 at 05:12 PM 0
Share

It was later discovered that my last else if statement was what was doing it. I had to change it to look to see if any other state was false before setting idle to true.

0 Replies

· Add your reply
  • Sort: 

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

Light switch trigger 3 Answers

Switching cameras (JavaScript) 0 Answers

Enum and Variable with similar name resulting in error 1 Answer

js switch case warning 1 Answer

Switch Statement question 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