Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 superventure · Jun 11, 2011 at 05:59 AM · rotationprefabquaternionparentchild

force child rotation to zero?

I've been trying to tackle this for far too long.. How do you force a child object to STAY at zero x rotation?

for some reason none of these work, and they are in an Update function too!

 transform.rotation.x = 0;
 transform.rotation.x = transform.root.rotation.x;
 transform.localRotation = Quaternion.identity; 

I only tried the last one to set it to the TOP parent's rotation. Didn't work! The rotation at best only keeps to the first parent's rotation. This prefab is a child of a child of a so and so forth.

what's up here? what am I missing? Thanks

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Wolfram · Jun 11, 2011 at 01:55 PM

First of all, transform.rotation refers to World space, while transform.localRotation refers to local space. The values you see in the Inspector are always local space, but just because they are zero doesn't mean the object has no rotation, because one of the parents might.

Secondly, localRotation, as the name suggests, only refers to the LOCAL rotation, that is, the rotation relative to its DIRECT PARENT. This is the reason your last method did what you explained it did, and not what you intended to do.

Most importantly, however, any variant of "rotation" always refers to the Quaternion. You cannot set/access individual angles with these, without calling additional conversion methods. Instead, when dealing with angles, use tranform.eulerAngles and transform.localEulerAngles.

You should be able to figure out the correct settings from the explanations above.

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 Anxo · Jun 11, 2011 at 01:47 PM

you mean relative to world space?

so if you have Box A as a child of Box B, and you rotate Box B,you want Box A to stay still on the X axis?

I would have guessed that transform.rotation.x would have worked as long as it is in an update function but if not you might be able to chat it.

What if you have a empty game object outside with the desired X rotation and you tell Box A, transform.rotation.x = EmptyGameObject.transform.rotation.x;

That seams very unnecessary, I think we are just missing some Space.World parameter but when I get a chance to test it I will check it 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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Make a simple tree 1 Answer

How to fix Child Object Rotations.? 1 Answer

Child versus Parent rotations 3 Answers

Pointing a child at an object using its parents rotation 1 Answer

Why is a child object not rotating properly with parent? 1 Answer


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