• 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

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

1 Person is following this question.

avatar image

Related Questions

Make a simple tree 1 Answer

How can I make a First Person Character Controller a child of a moving platform without it affecting the rotation of the Character Controller. 1 Answer

How to fix Child Object Rotations.? 1 Answer

Slider Controlled Rotation 1 Answer

Need help dealing with unruly children! 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