• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Rotate with joystick - LookAt axis flipping 1 Answer

Why this flip rotation only works for parent, but not child? 0 Answers

Why does the raycast hit only objects/faces of a certain rotation? 1 Answer

Make the character face the direction he is moving? 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges