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
0
Question by twoface262 · Feb 22, 2014 at 03:16 AM · rotationgameobjectchildeulerangles

How to parent an object without losing its rotation

Hello!

I'm having a very severe headache over this problem. I'm setting an objects rotation using transform.eulerAngles = new Vector3(transform.eulerAngles.x,transform.eulerAngles.y + 360,transform.eulerAngles.z);

But when I try to make the object that this code is attached to a Child of an object that is rotating in a circle then the Object that this code is attached to loses its rotation. This problem seems to only be occurring when the parent's rotation is something other than 0. Is there a fix to this problem? It's causing a major headache because I can't find the solution to this.

GameObject + Correct Rotation = Correct Rotation GameObject + non-rotating Parent + Correct Rotation = Correct Rotation GameObject + Rotating Parent + Correct Rotation = Incorrect Rotation

The GameObject is whose rotation I'm setting after I parent it. Thank you for the help!

Comment
Add comment · Show 4
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 whydoidoit · Feb 22, 2014 at 03:18 AM 1
Share

Well if you are parenting it, it will also assume it's parent's position and rotation - but you are overwriting it (every Update?) so it's a bit confusing.

avatar image twoface262 · Feb 22, 2014 at 03:42 AM 0
Share

No. I'm just calling the rotation once, AFTER it attaches to the parent. and it only attaches to the parent on start.

avatar image whydoidoit · Feb 22, 2014 at 03:44 AM 0
Share

BTW the code you posted appears to apply no additional rotation (+360 on the Y axis).

So are you saying it isn't following the rotation of the parent - or it is and that's not what you wanted?

avatar image twoface262 · Feb 22, 2014 at 04:03 AM 0
Share

Well what's really going on is once the object is assigned a parent then the object takes the parent's rotation. How would I make it to where that child never takes the parents rotation, and sticks to only one rotation? That's what I'm having trouble with.

1 Reply

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

Answer by robertbu · Feb 22, 2014 at 04:16 AM

One solution in situations like this is to not parent. Instead have the 'child' follow what would be the parent.

 var targetToFollow : Transform;
 
 function LateUpdate() {
    transform.position = targetToFollow.position;
 }

Now the pseudo-child follows the parent but does not rotate with the parent. If you need an offset, you can either specify it in code, or you can have the pseudo-child calculate it from the relative positions of the two object in Start().

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 whydoidoit · Feb 22, 2014 at 04:18 AM 1
Share

Agreed with Robert. You other choice is to capture the rotation and apply it every frame while still parenting the object:

     var myRotation : Quaternion;

     function Start() {
        myRotation = transform.rotation;
     }

     function LateUpdate() {
         transform.rotation = myRotation;
     }

This causes myRotation to be the actual rotation of the item.

avatar image twoface262 · Feb 22, 2014 at 04:22 AM 0
Share

No these are very un-useful. I don't want the child to follow the parent by any means. I want it to rotate with the parent. All the while doing movements of it's own. Sort of like an orbit, but I have many of these objects that must move in uniform with eachother which is why they all have their own rotations.

avatar image whydoidoit · Feb 22, 2014 at 04:24 AM 0
Share

Right in which case you need RotateAround and don't parent it - use that to move it.

avatar image whydoidoit · Feb 22, 2014 at 04:25 AM 0
Share

And really - it's not particularly reasonable to downvote an answer because we couldn't understand the question. You'll find people are unlikely to want to help you under those circumstances.

avatar image twoface262 · Feb 23, 2014 at 03:36 AM 0
Share

Again whydoit, that's unhelpful. I'm particularly experience with the engine and I've tried pretty much everything I could. Which is why I came here for an answer. I tried using RotateAround, but it didn't help at all because there are 8 of these objects that all need to be uniform meaning that they must all be the same distance apart and everything.

Show more comments

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

19 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Neutralising child rotations -> Parent 1 Answer

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

how to get the absolute direction? 1 Answer

How to freeze child gameobject rotation??? 2 Answers

Problem with child 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