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 Lazdude17 · Jun 02, 2014 at 02:36 AM · rotationflipface

2D character flipping issue

Hello,

When I press a button my character flips the direction I want and all is well as long as I am using the scaling method(Scaling -1 on x axis). But now I want to rotate the character by 180 degrees on the y instead. When I do though the character will flash for a second in the right direction and then face left again and stay left.

So when I press the Move Right Key my character flips for an instant and then flips back to facing left. I can continue to walk right but He will face left.

Here is all the flipping code

 void Update()
         {
             //Flip Direction
             if(horizontal > 0 && !faceRight)
             Flip ();
             else if (horizontal < 0 && faceRight)
             Flip ();
         }
 
         void Flip()
         {
             faceRight = !faceRight;
             transform.eulerAngles = new Vector3(0, 180, 0);
             return;
         }
Comment
Add comment · Show 2
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 Lazdude17 · Jun 02, 2014 at 06:46 PM 0
Share

Please Help!

avatar image UnityDevelopper · Jun 02, 2014 at 07:03 PM 0
Share

in the 2d character controller, this is how they did flip

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Fubiou · Sep 07, 2015 at 07:33 AM

Hey, I found a simple way to flip the 2d character with a simple line:

transform.localEulerAngles = transform.eulerAngles + Vector3(0,180,-2*transform.eulerAngles.z);

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 krispastas · Apr 28, 2019 at 10:08 AM 0
Share

Oh yeah that works

THAN$$anonymous$$ YOU SO $$anonymous$$UCH

avatar image
0

Answer by Lazdude17 · Jun 02, 2014 at 09:56 PM

I have already done that but it doesn't work with my current set up because I'm using Sprites & Bones package to get the IK functionality. It messes up the bones if you scale so I need to rotate instead but It will not work for me.

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 JDelekto · Apr 28, 2019 at 10:51 AM

Assuming that you're trying to do a mirror image flip, have you considered taking the component of your scale property and multiplying it by -1?

So if I have a sprite which is facing right, I can use transform.localScale = new Vector3(transform.localScale.x, -transform.localScale.y, transform.localScale.z).

If you can choose to do a 180-degree flip on any axis and combine them as well.

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

25 People are following this question.

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

Related Questions

Flip over an object (smooth transition) 3 Answers

Camera Rotation stay behind player and not flip 2 Answers

Sprite disapears when moving left 2 Answers

How would I rotate an object without moving one of its faces (locking it) 0 Answers

Rotate to face player, drunk issues 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