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 El-Psy-Congroo · Feb 08, 2017 at 04:06 PM · animation2danimatoranimator controller2d animation

My Anima 2D's flipped animations are bugging out.

I'm not sure what it is and sometimes there isn't a problem at all. This is how it looks going right which is the default - in other words, without changing scale:

https://twitter.com/3lPsyCongroo/status/828843021986832384/photo/1

The rootSpeed variable in the animator is just a check to see what the root of the character is doing. The varying between 38.7 and 35.8 has to do with curves on the animation and isn't what I'm worried about.

Now this is moving left, with the scale inverted:

https://twitter.com/3lPsyCongroo/status/828849556573937670

As you can see, the rootSpeed value in the animator is twitching - it seems like it is constantly changing from positive to negative. You can briefly see it reverse directions when the velocity is 0.

Here's the controller:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class MarionetteRootController : MonoBehaviour {
 
     Animator anim;
     Rigidbody2D rbody;
     float rbodyX;
 
     // Use this for initialization
     void Awake ()
     {
         anim = GetComponent<Animator>();
         rbody = GetComponent<Rigidbody2D>();
             
     }
     
     // Update is called once per frame
     void FixedUpdate ()
     {
         Move();
     }
 
     void Update()
     {
         Turn();
     }
 
     void LateUpdate()
     {
         GetRootSpeed();
     }
 
     private void Move()
     {
         anim.SetFloat("hSpeed", Input.GetAxisRaw("Horizontal"));
     }
 
     private void Turn()
     {
         if (Input.GetAxisRaw("Horizontal") < 0)
         {
             gameObject.transform.localScale = new Vector3(-1, 1, 1);
             anim.SetBool("facingRight", false);
         }
         else if (Input.GetAxisRaw("Horizontal") > 0)
         {
             gameObject.transform.localScale = new Vector3(1, 1, 1);
             anim.SetBool("facingRight", true);
         }
     }
 
     private void GetRootSpeed()
     {
         anim.SetFloat("rootSpeed", rbody.velocity.x);
     }
 
 }
 

I attempted to play around with the fixed update (before everything was in Update) but no difference. Here is the animator: alt text

The transition from Idle->Walk ->Run are the values for hSpeed (getAxis horizontal) AND facingRight while the transitions from Run->Walk->Idle are just hSpeed. The transition between Idle R and L are just based on facingRight. The Left facing animations are the same as the right facing ones. I'm testing out a system where the same animation is used for right and left but the sprites can be different - so as not to have to animate again. Hence why I'm flipping the x scale but still using separate animations for each direction.

capture.jpg (56.0 kB)
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 El-Psy-Congroo · Feb 08, 2017 at 12:07 AM 0
Share

So I sort of solved the flipping - now it doesn't randomly have a pose in the opposite direction. I realized in my code I didn't account for what it does when getaxisraw horizontal is 0 so I set it up to face the direction of the previous frame: using System.Collections; using System.Collections.Generic; using UnityEngine;

 public class $$anonymous$$arionetteRootController : $$anonymous$$onoBehaviour {
 
     Animator anim;
     Rigidbody2D rbody;
     bool prevFrameRight;
 
     // Use this for initialization
     void Awake ()
     {
         anim = GetComponent<Animator>();
         rbody = GetComponent<Rigidbody2D>();
         prevFrameRight = true;
             
     }
 
     // Update is called once per frame
 
     void Update()
     {
         $$anonymous$$ove();
         Turn();
     }
 
     void LateUpdate()
     {
         GetRootSpeed();
     }
 
     private void $$anonymous$$ove()
     {
         anim.SetFloat("hSpeed", Input.GetAxisRaw("Horizontal"));
     }
 
     private void Turn()
     {
         if (Input.GetAxisRaw("Horizontal") < 0)
         {
             gameObject.transform.localScale = new Vector3(-1, 1, 1);
             anim.SetBool("facingRight", false);
             prevFrameRight = false;
         }
         else if (Input.GetAxisRaw("Horizontal") > 0)
         {
             gameObject.transform.localScale = new Vector3(1, 1, 1);
             anim.SetBool("facingRight", true);
             prevFrameRight = true;
         }
         else if (Input.GetAxisRaw("Horizontal") == 0)
         {
             if (prevFrameRight)
             {
                 gameObject.transform.localScale = new Vector3(1, 1, 1);
             }
             else
             {
                 gameObject.transform.localScale = new Vector3(-1, 1, 1);
             }
         }
     }
 
     private void GetRootSpeed()
     {
         anim.SetFloat("rootSpeed", rbody.velocity.x);
     }
 
 }

Regardless, I still get the weird stuttering effect sometimes when it moves left. At times the amount is very small or nonexistent and at others its pretty bad. I kept the stats on for the gif files in case that lends anyone a clue. It can't be the animation itself because going right is fine and it uses the same clip to do so. Any suggestions?

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

2D Animation does not start 1 Answer

How to optimize 2D Animations created with 2D Animation packege? (v3.1.1) 0 Answers

2DAnimator Freezes first time an animation is played 0 Answers

How do I construct my animation state machine this way? 0 Answers

Animator Controller 2D RPG Best Practices 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