• 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 Dechcaudron · Mar 10, 2014 at 10:59 PM · rotationbugscaleparentissue

Child lossyScale changes after setting localRotation

Hey there Unity community! I've been working quite hard on a project lately with some colleagues, and I've just ran into something that I think might be a Unity bug itself. Anyways, I would love you to have a look at it and tell me if I've stuck my foot in at any point. This is the function causing the error:

 public void _Place (Transform a_parent, Vector3 a_coordinates, bool a_beKinematic = false)
         {
                 transform.parent = a_parent;
         
                 transform.localPosition = a_coordinates;
                 rigidbody.isKinematic = a_beKinematic;
 
                 //No parent, so the pickable is dropped
                 if (a_parent == null) {
                         transform.localEulerAngles = DropRotation;
                 } else {//Parented, so the pickable is equipped
                         transform.localEulerAngles = EquipRotation;
                 }    
         }

The point of the function is to parent / unparent the gameObject with this script attached to the one passed as a parameter. Because of some weird reason, when transform.localEulerAngles = EquipRotation happens (IE, the object has just been parented), the child (the gameObject running the script) changes its scale both numerically (which would make sense, given the fact that it has just been parented by an object with a scale different from (1,1,1)), AND graphically. This is, not only does it apply the localScale it should apply when being parented, but it also changes its global scale when set its localEulerAngles property.

This happens for setting both localEulerAngles and localRotation. If I comment out that line, everything works fine. I'm going nuts. Can somebody help me out?

Thanks beforehand

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 meeshanyah · May 02, 2014 at 03:42 PM 0
Share

Seems like I've ran into similar issue today and, as I'm very new to Unity and game development in general, wasted a whole day trying to understand why a projectile detached from a rotating parent gun changes its scale radically. Everything up to root from that projectile has scale (1, 1, 1).

I've noticed that the larger the degree the gun rotated (from Vector3.right or -Vector3.right, I'm builiding a 2D game) the lesser the scale becomes. Also I've noticed that at the moment of changing the projectile parent localScale stays (1, 1, 1), while lossyScales changes to some weird number, which localScale catches up later.

Since my math and Unity knowledge suffers, the only way I could solve this problem is by explicitely setting 'projectile.localScale' to (1, 1, 1).

Script reference on lossyScale states "If your objects are not skewed the value will be completely correct and most likely the value will not be very different if it contains skew too." $$anonymous$$aybe it's one of those not that likely cases? But I tend to think it's some fault on my side. Did you manage to understand what was happening?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by GameDevBryant · Oct 03, 2014 at 06:52 PM

I am running into this problem as well, and unfortunately I have not yet found a solution that I find ideal. I've been searching the forums trying to find a calculation or algorithm to reverse this.

Basically what is happening, is the transform of the gameObject becomes parented to something scaled non-uniformly and the rotation does not match which causes it to skew (scale is stored in 4 values, but the 4th is not visible/editable kind of like quaternions which accounts for the skew).

So the options I have seen to avoid this are to have the parent scaled uniformly (all the axes scaled the same), have the child and parent match their rotations, or have an intermediate empty game object with scale of (1,1,1) in between what is currently the parent and the child.

Good luck, and I hope that one of these will help you out!

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

22 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

Related Questions

Make child on the edge of the parent circle while scaling 0 Answers

Rotating an object within its parent's scale 0 Answers

Minor scale issue on play mode 0 Answers

Keyboard inputs randomly drop in Unity 5.4 2 Answers

Rotate both parent and child around parent 0 Answers

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