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 fddefdef · Jan 07, 2015 at 11:34 PM · spritefliplocalscale

Flip Y Scale Value Issue

Hi guys, i'm simply trying to flip my sprite upside down by changing the y scale value of it.

Here's the code i used that it's not working.

         if(rigidbody2D.velocity.x < 0f)
         {
             Vector3 tempScale = transform.localScale;
 
             tempScale.y = -1f;
 
             transform.localScale = tempScale;
         }
         else if(rigidbody2D.velocity.x >= 0f)
         {
             Vector3 tempScale = transform.localScale;
             
             tempScale.y = 1f;
             
             transform.localScale = tempScale;
         }

I'm sure that there's nothing in my entire solution that is overwriting the y scale value. I putted this code inside the Update function and i checked with a Debug.Log that Unity goes inside both if statements according to the x velocity of the rigidbody like i wanted, so i don't know what the error could be.

Please Help.

Comment
Add comment · Show 5
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 Glurth · Jan 07, 2015 at 11:57 PM 1
Share

Sorry, I don't see why that fails. Try a "sanity check" using debug to show the transform scale after you assign to it, perhaps that will offer a clue. Any particular reason you are using a negative scale, rather than rotating it? (note: negative scale should make a mirror image, rotating it should not. Is that why?)

avatar image Skeledurr · Jan 08, 2015 at 12:04 AM 1
Share

Try changing the scale in FixedUpdate and putting a Debug.Break(); after you call it.

This may help with debuging.

avatar image Baste · Jan 08, 2015 at 12:09 AM 1
Share

It might be that your velocity is being read as 0 at certain points, in which case the >= 0f condition will be used. As @Skeledurr said, FixedUpdate might help, but I'd also try to use a system that only changes the scale if it should change. That's a good idea anyways, now you're setting the scale every frame, when you really don't need to change it unless it's crossed from positive to negative or the other way around.

avatar image InvincibleCat · Jan 08, 2015 at 12:17 AM 0
Share

Is going in both parts regarding to your expectations? What is not working?

avatar image fddefdef · Jan 08, 2015 at 09:27 AM 0
Share

@Glurth I'm using a negative scale cause I need a mirror image of my sprite. Anyway thanks a lot guys for the quick answers, i will try all of your advices.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by george_vasilchenko · Jan 08, 2015 at 10:48 AM

Hey, everything works, just put

rigidbody2D.velocity.x <= 0f in the first if statement instead of just

rigidbody2D.velocity.x < 0f

Less or equal was the key. With me worked perfectly.

Comment
Add comment · Show 6 · 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 fddefdef · Jan 08, 2015 at 06:15 PM 0
Share

@hardwir3d unfortunately for me this solution doesn't work

avatar image george_vasilchenko · Jan 08, 2015 at 06:25 PM 0
Share

Then the problem must be outside of this block of code. Can you post some additional code u use?

avatar image fddefdef · Jan 08, 2015 at 08:33 PM 0
Share

@hardwir3d i already checked all the project and there is nothing that changes the y scale value. I also tried to change it on start function just to see if i could do it from there and i can't! How is that possible? Sorry anyway, i'm currently working for another one's project and i can only post very little parts of code.

avatar image InvincibleCat · Jan 08, 2015 at 08:35 PM 0
Share

Remove everything but your script. Is it working that way?

avatar image fddefdef · Jan 08, 2015 at 08:55 PM 0
Share

@InvincibleCat Just tried it. It still doesn't work.

Show more comments

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

30 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

2D Box Collider doesn't flip with Sprite 3 Answers

LocalScale not working idealy 1 Answer

My sprite is teleporting when I change my scale to -1 to flip it 1 Answer

Script to flip a sprite over the x axis not working? C#, Unity2D 1 Answer

Flip scripts not working anymore? 2 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