- Home /
Rotate parent so child is facing a specific rotation
Hi,
I have a parent cube with several small child cylinders, pointing out from the cube in each direction. I would like to rotate the cube so one of the child cylinders is facing in a specific rotation (basically I want the player to be able to select a child cylinder and that cylinder will determine the rotation of the parent cube).
I've tried several things, but it seems to be somewhat more complicated than what I thought initially. So I would very much appreciate if anyone has any thoughts that might help me.
Thanks a bunch, Simon
It seems I was able to solve my own problem:
connector.transform.parent.rotation = connector.transform.parent.rotation * Quaternion.FromToRotation(connector.transform.up, -_connector.transform.up);
Here the connectors are the child cylinders (connector is the child of the parent cube and _connector is the child of another cube I want to rotate the parent cube towards so both the connectors are looking at eachother!)
It's still an interesting question (with a descriptive subject! Not "Help with rotate") -- you may as well change the comment to an answer and mark it as correct.
Thanks, I will - I'm not too used to using this forum yet, but it seems like an awesome system :)
Answer by SMillard · Feb 16, 2012 at 12:01 AM
I found a possible solution:
connector.transform.parent.rotation = connector.transform.parent.rotation * Quaternion.FromToRotation(connector.transform.up, -_connector.transform.up);
(Here the connectors are the child cylinders (connector is the child of the parent cube and _connector is the child of another cube I want to rotate the parent cube towards so both the connectors are looking at eachother!))
Not a big deal, but can indent everything 4 spaces to get "code chunk format." It also seems cheater to check your own reply as the answer, but if someone does a search, an anwer-check turns the question green, making them more likely to read it.
yes I was going to check it as the answer, but an ad$$anonymous$$ needed to approve it first :)
thanks for the code chunk tip ;p