• 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 hedgefield · Sep 23, 2016 at 12:12 PM · animation2drotationcharacter controllerflip

Localscale-flipped 2D character retains original rotation since 5.4

Hey there, I have a problem with a 2D complex character rig going from Unity 5.3.6 to 5.4+.

I've looked around on the forums/google/answers and I see a lot of people with similar problems, but most solutions either don't work for me or were from two years ago or more.

So, I have a parent gameobject with an animator, 2D rigidbody, 2D box collider, and 2D character controller. Then a child with the torso sprite, and nested below that the limbs, head etc. None of the limbs have colliders on any other components except their sprite renderer.

For the running animation, I rotate the body a few degrees in the Z axis to make the character lean forward. This works great, all the limbs follow along, and the parent gameobject stays perfectly level.

Then when I switch directions, the controller script flips the root gameobject's localscale.

  private void Flip()
          {
              m_FacingRight = !m_FacingRight;
              Vector3 theScale = transform.localScale;
              theScale.x *= -1;
              transform.localScale = theScale;
          }

This flips the rig and the animation perfectly, but since Unity 5.4 the rotation values no longer flip with it. So when I run one way, everything is fine, but if I run the other way, the character leans way backwards.

I figured if this was a structural problem with the way I flip the rig or have it set up, it should have been present in 5.3.6 and below too, but it wasn't, it's a very clear difference upgrading to 5.4. Does anyone know what changed that Unity now handles this differently? Is there a workaround or should I stick with 5.3.6 for this project?

Thanks

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 PlayCreatively · Sep 23, 2016 at 12:31 PM 0
Share

Could we see the script that rotates the player. It shouldn't be too hard to make it a different value when facing the other direction.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by hedgefield · Sep 23, 2016 at 07:09 PM

This is the code in the character controller that gets triggered when you press left or right. The rotation on the body is done in an animation clip.

 private void Flip()
         {
             m_FacingRight = !m_FacingRight;
             Vector3 theScale = transform.localScale;
             theScale.x *= -1;
             transform.localScale = theScale;
         }
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
avatar image
0

Answer by maltadirk · Sep 27, 2016 at 10:36 AM

I'm running into the exact same problem. Tried messing around with transform.Translate but same issue. Have a feeling its to do with the new Animator which looks like it changed

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

2D sprite animation issue 0 Answers

How to properly flip 2D character with new Unity4.3 2D framework? (Have problem with animation rotation) 1 Answer

2D rotation question 0 Answers

Animation in Unity editor prevents rotation in script 1 Answer

Animated sprites disappear then rotated on Android 6 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