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 Darth-Zoddo · Apr 15, 2016 at 11:39 AM · animationbooleansimple

Animation gets stuck in the last frame for 2 secs.

So i'm working with animations through code and not with mecanim. Until now everything works fine (transition between animations is still horrible), the problem that i'm having is when the BA1 animation gets called. When it gets called it's plays perfectly untill the last frame. When it hits the last frame it gets stuck for 2 secs. After about 2secs the IDLE animation gets played.

I want that the IDLE animation gets played right after the BA1 animation is finished playing. Instead of it getting stuck for 2 secs and then the IDLE gets played I don't know if this is a bug in unity or that it's just me being a newb at coding.

Here's the script:

 var ForwardSpeed : float    = 20;
 var SideSpeed     : float     = 13;
 var BA              : boolean  = false;
 var Walking      : boolean  = false;
 var IDLE         : boolean  = false;
 var Running      : boolean  = false;
 
 function Update () {
 
     var forward : float = Input.GetAxis ("W") * ForwardSpeed;
     var side     : float = Input.GetAxis ("Horizontal") * SideSpeed;
 
     forward *= Time.deltaTime;
     side *= Time.deltaTime;
         
     transform.Translate (0, 0, forward);
     transform.Translate (side, 0, 0);    
          
     if (Walking){
         IDLE      = false;
         Shooting = false;
         Running  = false;
         }
         
     if (BA){
         Walking = false;
         IDLE     = false;
         Running = false;
         }
         
     if (IDLE){
         Walking  = false;
         BA       = false;
         Running  = false;
         }
         
     if (Running){
         IDLE     = false;
         Walking  = false;
         BA       = false;
         }
         
     if (Walking == false && BA ==false){
         idle();
         }
         
     if(Input.GetButtonDown("W")){
          WalkingForward();
          }
      
     if (Input.GetButton("Fire1")){
         BasicAttack();
         }
         
     if (Input.GetButtonDown("space")){
         Sprinting();
         }
         
     if (Input.GetButtonUp("space") && Input.GetButton("W")){
         WalkingForward();
         }
 
     if (Input.GetButtonUp("W")){
         Walking = false;
         }
 
     //if (Input.GetButtonUp("Fire1")){
         //BA = false;
         //}
         
     if (Input.GetButtonUp("space")){
         Running = false;
         }
 }
     
 function idle (){
     GetComponent.<Animation>().Play("IDLE");
     IDLE = true;
 }
 
 function WalkingForward (){
     GetComponent.<Animation>().Play("Walk");
     Walking = true;
     ForwardSpeed = 8;
     SideSpeed    = 8;
 }
     
 function BasicAttack (){
     BA = true;
     GetComponent.<Animation>().Play("BA1");
     yield WaitForSeconds(GetComponent.<Animation>().clip.length);
     BA = false;
 }
 
 function Sprinting (){
     GetComponent.<Animation>().Play("Sprint");
     Running = true;
     ForwardSpeed = 15;
     SideSpeed    = 15;
 }
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
Best Answer

Answer by Immanuel-Scholz · Apr 15, 2016 at 01:19 PM

Instead of calling to BasicAttack() in line 52, you should start it as a coroutine, because you are using "yield" inside the function.

But seriously. You should really really switch to Mecanim, especially for state machines like this one. No excuses!

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 Darth-Zoddo · Apr 18, 2016 at 07:28 AM 0
Share

would i have to change line 52 to: StartCoroutine(BasicAttack(2.0));

or won't this help?

and yes i am planning on using mecanim, but i want to learn a bit more about coding animations etc ;)

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

Jump animation anticipation 2 Answers

Can the animation editor create local rotational data? 3 Answers

Keep boolean true whilst playing animation, then false 1 Answer

Add a bool to animator & activate by key press 1 Answer

Animator parameter stuck as True 4 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