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 icywater · Jan 01, 2012 at 06:45 PM · rotationupdateparentchild

Making world rotation of a child object fixed efficiently...

I have an object which is parented under another object. And I want the childs world rotation to be fixed at (0,0,0). I know I can do:

 Update() {
  transform.rotation = Quaternion.identity;
 }


But that would be really inefficient. Is there a way to disable rotation inherited from the parent from Awake() or Start(). That way I only have to do it once, instead of every frame.

PS. I dont want to attach a rigidbody and put on constraints. A solution in code would be better.

Thanks!

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 tomekkie2 · Jan 01, 2012 at 08:22 PM 0
Share

I think there is no other solution then you are actually doing or just to break the parenting and follow the transform.position only of the parent so far on Update.

avatar image icywater · Jan 02, 2012 at 06:58 AM 0
Share

there isnt any way to constraint rotation without a rigidbody?

2 Replies

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

Answer by Eric5h5 · Jan 02, 2012 at 07:22 AM

The definition of a child is that it inherits position and rotation from the parent, so if you don't want to reset rotation every frame, then it shouldn't be a child in the first place. There's nothing magical about rigidbody constraints, though; I expect they do pretty much what your code is doing.

Comment
Add comment · Show 2 · 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 icywater · Jan 02, 2012 at 05:55 PM 0
Share

oh ok. thanks

avatar image chronodm · Oct 14, 2016 at 02:01 AM 0
Share

I don't think adding a RigidBody works — AFAICT freezing rotation on a rigidbody freezes it relative to the parent.

avatar image
0

Answer by IMD · Apr 15, 2014 at 01:43 PM

When you want to leave the gameobject as a child for 99 other reasons, you can true rotate it independently of the parent by adjusting the child's local rotation by its parents rotation and then apply the true desired 'global rotation' to the child. Here's some code I wrote to do do this:

 transform.localRotation = Quaternion.Euler(-transform.parent.rotation.eulerAngles + trueRotation);

Hope you find it helpful.

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 SpaceManDan · May 03, 2016 at 03:19 AM 0
Share

maybe I'm dumb but trueRotation here is the rotation we are converting to the new rotation? I'll try it out and see if it works.

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Make a simple tree 1 Answer

Changing child's rotation changes parent's position 0 Answers

Child/parent rotation problem 1 Answer

how do I get Parent rotation on Child,how do I use a parents rotation in a child? 2 Answers

Parent object to face childs rotation... 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