- Home /
Quaternion to rotate a GameObject and its children
Hey, I have a given Quaternion (with the new direction of one GameObject, calles rotation) and 3 GameObjects, where each is a child of the other. I have now by using: GetComponentsInChildren() --> transformObjects (length 3).
Now, I want to change the rotation of the parent with my rotation Quaternion, that is given and also all kids in respect to the parent.
In the case, that I say transformObjects[0].rotation = rotation; It is moving the GameObject far away from the scene and is doing a rotation.
Why, is it moving the GameObject far away, when I use the Quaternion (rotation). And how can I change the postion of the Children in respect to the changes of the parent?
You can see in the picture above, my 3 GameObjects (a finger). My Quaternion is the rotation of the first Part of the fingern. E.g. it can rotate the finger up and the other 2 parts (chirldren) need to move with it.
Can someone help?
So, you are getting parent and children transform components with
private Component[] transformArray;
void Start()
{
transformArray = gameobject.GetComponentsInChildren<Transform>()
}
and changing parents rotation somewhere in your code with
transformArray[0].rotation = rotation;
and parent gameobject's position and rotation changes? Doesn't make sense. Is it possible for you to provide the code that you manipulate rotation?
Children will always move with their parent -- that's how the transform hierarchy works!
I'm not sure if we're understanding your question correctly. You say you want to rotate a parent and its children, but the default behavior when rotating is to do exactly that.
You ask "Why is it moving the GameObject far away?" but that's hard to say without seeing some more information. Either you're doing more than just rotating, or your rotation is around an unusual pivot point.
Answer by Levithan6785 · Nov 05, 2015 at 06:36 PM
Anything done to the parent affects the children. If you rotate the parent, the children rotate too. If you scale a parent, it will scale the children. Values changed by the parent does not change values inside the children.
Your answer
Follow this Question
Related Questions
When creating joints during game play how do you change the position and rotation of an object. 0 Answers
Instantiate GameObject to specific position on the Parent 2 Answers
Offset position to a target 3 Answers
blocks being placed in an odd way 0 Answers
How to position objects UI elements in a line accounting for the rotation of the object 1 Answer