- Home /
rotate parent object to straighten child object?
i have a parent object that contains mixed childs of different rotations, (treetrunk and branches) i want to rotate the parent so that the main child, the tree trunk looks straight upwards.
If tree trunk points towards Vector3 ( 3,6,8);
how can i rotate parent object so that tree trunk points to Vector3.up ?
i thought i would have figured this out by now, but i couldn't.
Answer by drudiverse · Jul 04, 2014 at 09:25 PM
Ok this works for certain and it is easy to visualise... find a perp vector to the from and to that you want, and rotate the GO by x degrees around the perpendicular axis:
cross = Vector3.Cross(Vector3.up, trunkispoiting);
angle = Vector3.Angle(Vector3.up, trunkispointing);
fractalTree.transform.RotateAround( Vector3.zero,cross,-angle);
this may work also... not tested:
p2.rotation = Quaternion.Inverse(c2.localRotaion)*c1.rotation; or p2.rotation = c1.rotation*Quaternion.Inverse(c2.localRotaion);
Answer by Lazdude17 · Jul 04, 2014 at 04:06 PM
Idk why you would do this but wouldn't you just rotate the parent, (x-3,y-6,z-8)? One of those may need to done again depending on the way the tree is facing though.
Because i found a great formula to generate many tree shapes with many relative angles, except the formula makes the tree point in different 360 directions, so i would like to keep the formula the same, and rotate the tree object afterwards.
i should do:
var relativepos = Vector3.up - Vector3.trunkvector;
treeGameObject = Quaternion.LookRotation(relativepos);
it doesn't work.
Your answer
Follow this Question
Related Questions
Make a simple tree 1 Answer
Child ignoring parent rotation? 1 Answer
How can I identify a non-uniform scaled mesh, and fix it? 1 Answer
How to fix Child Object Rotations.? 1 Answer