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
1
Question by Stone-Legion · Jun 27, 2014 at 06:07 PM · c#2drotation2d-platformermirror

Flipping parent object in 2d with negative x scale causes rotation issues for children gameobjects

When I flip my my parent game object from positive x to -x image size to mirror and make it appear as if the image went from moving left to right, the children game objects no longer rotate properly when using a rotation script. It appears that it isn't just rotating improperly but rotating in a weird way altogether. I'm using Unity 4.5.1f3, I know there was a problem with 2d collider rotation but this seems to be outside of that because the entire game object is rotating abnormally.

Does anyone know how to overcome this problem?

Script for arm rotation, arms are attached to parent game object. When the parent flips size from positive to negative, the image mirrors and all children flip as well, but when rotating, problems occur:

 void Update ()
     {
         target = this.transform;
         mouse_pos = Input.mousePosition;
         mouse_pos.z = 0f; //The distance between the camera and object
         object_pos = gameManager.mainCamera.WorldToScreenPoint(target.position);
         mouse_pos.x = mouse_pos.x *-1.0f - object_pos.x;
         mouse_pos.y = mouse_pos.y - object_pos.y;
         angle = Mathf.Atan2(mouse_pos.y, mouse_pos.x) * Mathf.Rad2Deg;
         transform.rotation = Quaternion.AngleAxis( angle+105.0f, Vector3.forward);

      }
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 Ash-Blue · Nov 14, 2014 at 12:51 AM 0
Share

Exact same problem, has anybody come up with a solution for this?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by IvovdMarel · Jun 27, 2014 at 06:47 PM

Try changing transform.rotation to transform.localRotation

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 Ash-Blue · Nov 14, 2014 at 12:51 AM 0
Share

First thing I tried, but for some odd reason it does nothing :(

avatar image
0

Answer by Pyrian · Nov 14, 2014 at 04:47 PM

The Atan2 call is not aware of the flip, so it returns an unflipped result. You pass that unflipped result into the rotation value, which is then modified by the scale to flip it. This of course results in a value that's flipped from what you want it to point at.

You'll have to manually flip the angle you're passing while the sprite is flipped.

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

24 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

Related Questions

Flip over an object (smooth transition) 3 Answers

How to turn off a collider when I activate it (Basic Sword mechanic) [2D] 2 Answers

2D multi touch 1 Answer

Unity C# 2D Adding Velocity on rotation 1 Answer

How do i make a one gun only Weapon system. (2D) 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