- Home /
The question is answered, right answer was accepted
Parent transform not following child transform
I do not have much experience with Unity.
I have a parent gameObject A, with a transform component and a script. These parent A has several child gameobjects, each one of them is a cube, composed by a collider, a rigidbody and a joint, which connects them to each other.
I apply forces to the cubes so they reach a specific local position. However the position of the parent gameObject A, in the inspector does not change, even when other objects are throwned at the cubes, moving them to different world positions. But the gizmo in the center of the parent A, in the scene view, clearly moves as the cubes move.
How can I make the position of the parent gameObject A change simultaneously with the movement of the cubes?
First gif shows the behaviour, and it is possible to see that in the editor the position of the parent does not change, however the gizmo changes. The problem here is that the character returns to its original position, when it should return to the original relative position, if the parent position changed correctly.
https://giphy.com/gifs/l0Iy4FCqWReXC47kI
The second gif shows the exact same situation, but initially by moving the parent position, when the dummy returns to the original position, it returns to the position of the parent.
in upper left corner, you will see "center" and "local" buttons.
click on "center" and it will change to "pivot".
in center mode, unity shows handle at the center of all children/geometry.
in pivot mode, unity shows handle at the actual position shown in the inspector.
Yeah but this really does not change the behaviour.
What I want is to be able to observe differences on the parent transform, but in the inspector that tranform values never change, and that's my problem.
I need the parent transform (x,y,z) values to change simultaneously with the changes of the transforms of the children.
The children position are calculated based on the parent position, since they're local positions, if this parent position never changes, the children will always return to the same global position, and that's not what I intend.
Normally moving a child object should NOT affect the parent object. However you mentioned that you have joints connecting the parent and children, which COULD change this behavior. There are lots of factors that go into defining a joint, perhaps it is misconfigured? Please show us how you have your joints setup.
I don't have any joint connecting the children with the parent. I have joints connecting the children with themselves.
However I already tried to used a fixed joint to connect the parent with a child object, but eventhough the parent changes its position correctly, the rest of the children can no longer reach the desired local positions.
This gif below shows that: https://giphy.com/gifs/l0Iyl4h95EAs$$anonymous$$s5Gw
Ah, that's probably because the function that adds the forces is not expecting the parent object to change position (which in turn changes the positions of the children objects). If this is the case, I'm not sure you'll be able to make this work, without adjusting that add forces routine. (I suspect the add force routine is using the object's "position"[world-space], rather than object's "localPosition"[relative to parent].)
Why do you WANT the parent object position to change? Could you just use the position of say... the torso, for your purposes?
Follow this Question
Related Questions
Separate child rotation 1 Answer
Moving parent to position of child 0 Answers
Problem with making child an object 2 Answers
Make a simple tree 1 Answer