• 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
0
Question by Easy · Oct 08, 2010 at 10:18 AM · rotationparentchild

parent child rotation

Hi,

I have a gameobject which is parent of other gameobject,so i have parent and child objects.

I want to be able to rotate the parent object but to leave child object to always look up direction.

When i rotate the parent object i can see its euler value change,but the child object is always (0,0,0).

How can i make the child object to look some vector( let say up ) constantly?

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
1

Answer by runevision · Oct 08, 2010 at 10:28 AM

You can place a script on the child object that makes it be aligned the way you want.

// To keep a constant global rotation:
var myGlobalRotation : Vector3;
function Update () {
    transform.rotation = myGlobalRotation;
}

Or:

// To make the object z axis look at some point:
var myLookAtTarget : Vector3;
function Update () {
    transform.LookAt(myLookAtTarget);
}

Or:

// To make the object y axis keep pointing up:
function Update () {
    transform.up = Vector3.up;
}
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 Easy · Oct 08, 2010 at 11:03 AM 0
Share

Hi, I have tried transform.up = vector3.up but my child object is skewed. All other method change my object to face to some unwanted direction and i dont know how to fix it. what i miss here?

avatar image runevision ♦♦ · Oct 11, 2010 at 10:01 AM 0
Share

You probably have a non-uniform scaling on the parent transform then. You should avoid that as it creates all kinds of problems.

avatar image
0

Answer by Bretfort · Nov 30, 2012 at 08:58 PM

you need to remember your camera's rotation:

     void Start () {
         fixedRot = gameObject.transform.rotation;
     }
     
     // Update is called once per frame
     void Update () {
         gameObject.transform.up = fixedRot;
     }
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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

Make a simple tree 1 Answer

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

Need camera to follow player, but not the player's rotation. 13 Answers

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

Child/parent rotation problem 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