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 noonoox · Jun 30, 2015 at 12:17 PM · animation2dunity5mecanim

Select Animations Freezing on First Frame

To start, yes; other people have asked this question, but those other people either A. have not been answered or B. did not use Mecanim, so it's hard to tell if their solution is the correct one.

At some point, seemingly without reason, all of my animations except for my idle animations freeze on frame 1 and, therefor, do not exit at end of when the animation should finish.

I have removed, edited, and completely scrapped all related code, restarted Unity multiple times, and completely remade my animations and Mecanim setup twice; none of these have worked, however.

Here are the related scripts:

 public class Entity:MonoBehaviour{
 
     public Animator animator;
     public Rigidbody2D rigidbody2D;
     public float direction;
 
     public int maxHP = 3;
     public int HP = 3;
     public int maxStamina = 10;
     public int stamina = 10;
     public string name = "Enemy";
 
     public float moveSpeed = 1;
     public float recoverSpeed = .75f;
     public int state = 2;
     public bool isThrust = false;
     public bool isReact = false;
     public bool isParry = false;
     public float timer;
     public bool timerOn = false;
     public float animTimer;
     public bool animTimerOn = false;
 
     public virtual void Start(){
         animator = GetComponent<Animator>();
         rigidbody2D = GetComponent<Rigidbody2D>();
         GetComponent<SpriteRenderer>().color = new Color(Random.Range (0.1f, .99f), Random.Range (0.1f, .99f), Random.Range (0.1f, .99f), 1);
     }
 
     public virtual void Update(){
         if(!timerOn){
             if(timer <= 0){
                 timer = Random.Range(.1f, 3);
                 state = Mathf.RoundToInt(Random.Range(.6f, 3.4f));
             }else{
                 timer -= Time.deltaTime;
             }
         }else if(timerOn){
             if(timer > 0){
                 timer -= Time.deltaTime;
             }else{
                 timerOn = false;
                 isThrust = false;
                 isReact = false;
                 isParry = false;
             }
         }
 
         animator.SetFloat("State", state);
         animator.SetBool("IsThrust", isThrust);
         animator.SetBool("IsReact", isReact);
         animator.SetBool("IsParry", isParry);
     }
 
     public void Flip(){
         transform.localScale = new Vector2(transform.localScale.x * -1, transform.localScale.y);
     }
 
     public void Thrust(){
         isThrust = true;
         isReact = false;
         isParry = false;
         timer = .625f;
         timerOn = true;
     }
     
     public void React(){
         isThrust = false;
         isReact = true;
         isParry = false;
         timer = .5f;
         timerOn = true;
     }
 
     public void Parry(){
         isThrust = false;
         isReact = false;
         isParry = true;
         timer = .5f;
         timerOn = true;
     }
 
     public void OnTriggerStay2D(Collider2D other){
         if(isThrust){
             if(!animTimerOn){
                 animTimerOn = true;
                 animTimer = .25f;
             }else if(animTimer > 0){
                 animTimer -= Time.deltaTime;
             }else{
                 animTimerOn = false;
 
                 if(other.tag == "Entity"){
                     Entity entity = other.GetComponent<Entity>();
 
                     print(entity.name + " is in combat!");
 
                     int dirTo = transform.position.x - entity.transform.position.x > 0 ? 1 : -1;
 
                     if(entity.state != state){
                         entity.Parry();
                         entity.HP--;
                         entity.rigidbody2D.velocity = new Vector2(recoverSpeed * .5f * -dirTo, 0);
                     }else{
                         React();
                         entity.Parry();
                         rigidbody2D.velocity = new Vector2(recoverSpeed * dirTo, 0);
                     }
                 }
             }
         }
     }
 }


along with the player script,

 public class Player:Entity{
 
     public bool leftDown = false;
     public float leftDownTime;
     public bool rightDown = false;
     public float rightDownTime;
 
     public void OnEnable(){
         name = "Player";
     }
 
     public override void Update(){
         direction = transform.localScale.x;
 
         if(!timerOn){
             if(Input.GetMouseButton(1)){
                 state = 1;
             }else if(Input.GetMouseButton(0)){
                 state = 3;
             }else{
                 state = 2;
             }
             
             if(Input.GetButtonDown("Space")){
                 Thrust();
                 return;
             }
 
             if(Input.GetButton("Horizontal")){
                 //isMove = true;
                 //timer = .3f;
                 //timerOn = true;
                 rigidbody2D.velocity = new Vector2(moveSpeed * Input.GetAxisRaw("Horizontal"), rigidbody2D.velocity.y);
 
                 if(direction != Input.GetAxisRaw("Horizontal")){
                     //Flip();
                 }
 
                 //Vector2.Lerp(transform.position, new Vector2(transform.position.x + Input.GetAxis("Horizontal"), transform.position.y), moveSpeed * Time.deltaTime);
             }else{
                 rigidbody2D.velocity = new Vector2(0, rigidbody2D.velocity.y);
                 //isMove = false;
             }
         }else{
             if(timer > 0){
                 timer -= Time.deltaTime;
             }else{
                 timerOn = false;
                 //isMove = false;
                 isThrust = false;
                 isReact = false;
                 isParry = false;
             }
         }
 
         animator.SetFloat("State", state);
         //animator.SetBool("IsMove", isMove);
         animator.SetBool("IsThrust", isThrust);
         animator.SetBool("IsReact", isReact);
         animator.SetBool("IsParry", isParry);
     }
 }
 

Any help would be highly appreciated

Comment
Add comment · Show 3
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 noonoox · Jul 01, 2015 at 04:16 PM 0
Share

Update: I made a completely new project and redid the code, animations, and mecanim layout completely to no avail. the problem persists.

avatar image FortisVenaliter · Jul 01, 2015 at 07:02 PM 0
Share

Can you include some screenshots of the animations in the inspector, how they're imported, and the animator controller for at least one of the problem animations? The code looks okay, at first glance, so the problem might be in the components setup.

avatar image Rellfy · Jul 01, 2015 at 10:17 PM 0
Share

Try to use LateUpdate insead of Update, it may work

1 Reply

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

Answer by noonoox · Jul 03, 2015 at 04:54 AM

Hey guys, sorry to waste your time. I rewrote my code and, while I'm still not entirely sure, I believe it was caused by some strange bug of me using all those bools instead of triggers

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How do you check to see if an animation is playing in a Sub-State machine? 0 Answers

mecanim dynamic animation choice 0 Answers

Mecanim issue with mirror animations and blend 1 Answer

Is there a way to optimize animators? 3 Answers

Create 2D box colliders based on current frame of animation 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