Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
2
Question by Lord Simpson · Aug 08, 2011 at 02:34 PM · rotationquaternionparentchild

Pointing a child at an object using its parents rotation

Hi I have a system where an object's child has to face a target I require the entire object to be rotated so the child is facing the target but cant seam to work out the correct quaternion combination. I currently have this which seams to work fine except in some odd circumstances.

     transform.rotation = Quaternion.RotateTowards(transform.rotation,
                                transform.rotation * Quaternion.FromToRotation(
                                       child.transform.forward,
                                             target.position-child.transform.position)
                                                     ,temprotspeed * Time.deltaTime);


I know I basically need to apply a rotation that is zero when the child is facing the object but cant seam to work it out...and im sure its something rather easy...

Any help would be appreciated

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 Lord Simpson · Aug 08, 2011 at 03:30 PM 0
Share

Also just to note encase it wasn't obvious the child is facing a different direction to the parent. In this case I could just point the parents right vector towards the target, but I require a more general formula as not all the children will be pointing right...and most wont even be on a clean vector like right or up.

avatar image Lord Simpson · Aug 08, 2011 at 05:00 PM 0
Share

thought i had it figured out but this doesnt work although im sure it should

transform.rotation = Quaternion.RotateTowards(transform.rotation,Quaternion.FromToRotation(child.forward,transform.forward) Quaternion.LookRotation (transform.position-target.position,turnspeed Time.deltaTime);

$$anonymous$$y thoughts where to get the rotation difference between parent and child [so the child is effectively the forward vector] then rotate that to face the target....but doesn't seam to work either...

avatar image Lord Simpson · Aug 08, 2011 at 10:54 PM 0
Share

Ok Almost got this working

                 Vector3 childForward= target.transform.position - child.transform.position);
                 Vector3 childRight = Vector3.Cross (childForward, child.transform.up);
                 Vector3 childNewUp = Vector3.Cross (right, forward);
                 transform.rotation = Quaternion.RotateTowards (transform.rotation, Quaternion.LookRotation (childRight , childNewUp), rotationSpeed);

but this only works for one side as childRight and childNewUp always return the same no matter if childForward is to the right or the left...need some way to change the sign of one of the Cross's to relate to the facing of childForward or maybe change the maths somehow to incorporate the direction of childForward

avatar image drudiverse · Jul 04, 2014 at 09:29 PM 0
Share

I found this question and am abit manic about completing questions on unity reference so that they are useful for others one day... here is a solution to rotate a parent object, so that child transform upwards faces world vector3.up, although it could be any target vector:

      cross = Vector3.Cross(Vector3.up, trunkispoiting); 
      angle = Vector3.Angle(Vector3.up, trunkispointing); 
      fractalTree.transform.RotateAround( Vector3.zero,cross,-angle); 

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ChiuanWei · Aug 08, 2011 at 03:20 PM

how about using this Function instead :

var relativePos = target.position - transform.position; var rotation = Quaternion.LookRotation(relativePos); 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 Lord Simpson · Aug 08, 2011 at 03:28 PM 0
Share

unless I'm mistaken that would just point the parent at the object not the child?

avatar image ChiuanWei · Aug 09, 2011 at 12:16 PM 0
Share

var relativePos = target.position - child.transform.position; var rotation = Quaternion.LookRotation(relativePos); child.transform.rotation = rotation;

that will be child . have try?

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to fix Child Object Rotations.? 1 Answer

Child versus Parent rotations 3 Answers

force child rotation to zero? 2 Answers

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


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