Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 firasdeep · Oct 13, 2011 at 01:37 PM · rotationgameobjectchildfreeze

How to freeze child gameobject rotation???

Hello I have 2 gameobject the first one is parent and the second is child ,, if the parent gameobject rotate the child gameobject rotate too, and I want to freeze the child object from rotation...

thx..

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
12
Best Answer

Answer by aldonaletto · Oct 13, 2011 at 03:03 PM

I didn't test this, but I believe that you can just set the child transform.rotation to a fixed value in LateUpdate to eliminate any parent-originated rotation. You can save the initial child rotation at Start, like below (attach this to the child):

 var iniRot: Quaternion;
 
 function Start(){
     iniRot = transform.rotation;
 }
 
 function LateUpdate(){
     transform.rotation = iniRot;
 }


NOTE: If the parent is being moved by physics you may have problems, because physics runs at its own pace, and a cycle may occur between LateUpdate and the scene rendering.

Comment
Add comment · Show 6 · 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 firasdeep · Oct 13, 2011 at 05:25 PM 0
Share

Thx...very much....

avatar image MiraiTunga · Jan 22, 2013 at 04:38 PM 0
Share

thanks for the script !..was having same problem

avatar image Tito Trujillo · Feb 08, 2016 at 04:53 AM 0
Share

$$anonymous$$any thanks to you sir.

avatar image SaturnoMichael · Jun 30, 2016 at 11:41 PM 0
Share

Gracias, el efecto final es increíble.

avatar image andyjoe · Sep 03, 2017 at 06:33 PM 0
Share

Liking the simple solution. But what if I want to freeze the X and Z axis only? I get an error when using transform.rotation.y = rotation.y ?

avatar image aldonaletto andyjoe · Sep 04, 2017 at 03:32 AM 0
Share

Transform.rotation is a Quaternion, not those nice angles we see in the Inspector's Rotation field (they are actually the Transform.eulerAngles), and modifying its components only produces weird and unexpected results.
You could try to save the Transform.eulerAngles ins$$anonymous$$d of Transform.rotation, and only restore x and z:

  var iniRot: Vector3;
  
  function Start(){
      iniRot = transform.eulerAngles;
  }
  
  function LateUpdate(){
      iniRot.y = transform.eulerAngles.y; // keep current rotation about Y
      transform.EulerAngles = iniRot; // restore original rotation with new Y
  }

But this may fail miserably if the object rotates "too much" - as you may have already noticed, the Inspector's Rotation field may jump weirdly when any of the angles crosses multiples of 90 degrees.

avatar image
5

Answer by firasdeep · Oct 14, 2011 at 03:39 AM

this script work . attach with child object ... :)

     function Update () {
 var rotation = Quaternion.LookRotation(Vector3.up , Vector3.forward);
 transform.rotation = rotation;
 }
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 Alexei_UA · Mar 07, 2017 at 09:21 PM 0
Share

But not working if I use "AddForce" to this object

avatar image shottogan Alexei_UA · May 31, 2017 at 08:05 PM 0
Share

You need to modify the rotation of the attached rigidbody as opposed to transform. IE:

 RigidBody rb;
 
 function void Awake() {
     rb = GetComponent<RigidBody>();
 }
 function void FixedUpdate() {
     rb.rotation = rotation;
 }

:0)

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

14 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

Related Questions

How to parent an object without losing its rotation 1 Answer

Neutralising child rotations -> Parent 1 Answer

How to change child's rotation whithout affecting it's scale? 1 Answer

Freeze specific rotation axis of a child 2 Answers

Issue with an object rotating strangely 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