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 Bangel1423 · Jun 13, 2014 at 07:57 AM · c#2dmousescale

2D sprites, Negative scaling flips my look at mouse

Hello,

I have been working on a 2D side scroller using the new 2D system introduced with the newer version of unity.

I was following the Brackeys brief unfinished tutorial on it and he downloaded and imported the 2D folder of the Sample Assets (Beta) package released from unity. Link here

We are using the character movement script that came with it and in it, it checks if you are going left or right and it scales the character along the X negatively if you're going left.

 void Flip ()
     {
         // Switch the way the player is labelled as facing.
         facingRight = !facingRight;
         
         // Multiply the player's x local scale by -1.
         Vector3 theScale = transform.localScale;
         theScale.x *= -1;
         transform.localScale = theScale;
     }

In the tutorial Brackeys has a mouse script that he puts on the arm which is a child of the main character sprite:

 public class ArmRotate : MonoBehaviour 
 {
     public int rotationOffset = 90;
     //public float maxZ = 40f;
     //public float minZ = 335f;
     // Use this for initialization
     
     // Update is called once per frame
     void Update () 
     {
         Vector3 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
         difference.Normalize();
 
         float rotZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;
         transform.rotation = Quaternion.Euler(0f, 0f, rotZ + rotationOffset);
     }
 }


The arm rotates perfectly when looking right, but the issue happens when we look left and he scales to -1. The arm, instead of looking at the mouse position he looks at the correct position, but because of his negative scale its opposite on the X and I have no idea how to fix it...

If anyone could shed some insight on how to fix this I would be more than grateful.

Thank you.

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 bob1234 · Jun 13, 2014 at 05:18 PM 0
Share

Idk if this helps, but have you tried setting "rotationOffset" to 0 in the inspector? i think he mentions this in his video aswell

avatar image Bangel1423 · Jun 14, 2014 at 04:41 AM 0
Share

Oh yeah, without it being at 0 it doesn't face the mouse (when facing right) but that variable has no effect when facing left :/

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

How to keep my cursor inside window boundaries 0 Answers

How to make 2d distortion? 2 Answers

If i click on a object i move to the next level (c#) 0 Answers

Apply force towards mouse click 2D C# 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