unity parent relative to child position and rotation - unity3d

I've looked around for some ideas on this to no avail. I have a scene in unity where a parent has four children positioned and rotated in relation to the parent (though not necessarily the same position and rotation as the parent). After moving and rotating the parent, the children should follow the parent, and reset their position and rotation in locally similar way to parent as before, preserving a similar formation. In particular, I can get the children to follow the parent, but once the parent reaches their destination, I don't know how to reset the children to their appropriate formation positions and rotations once the goal is reached. I'm not looking for someone to answer my question as much as a headstart on how to make this happen. Any help is greatly appreciated. Thanks everyone.

Assuming you have a script on your parent,
One approach will be to store the Transforms of the Children before the Parent starts to move and after reaching the destination, apply the Transform back to the children :)
[Child's transform is relative to the parent, so the child will be displaced if the parent is rotated since child is not at (0,0,0) relative to the parent]

Related

Parent Game Object to Follow Child

Is there a way to have a parent object follow the combined bounds box of the child objects?
I have child objects which I apply force to for movement (via `AddForceAtPosition). The problem is that they leave the parent behind in world space. I understand that children are relative to the parents position. But is there anything I can do to address this?
I'd really like to keep to keep the force being applied to the child object's rigid bodies as it gives me the physics behaviour I need.
I have experimented with getting the bounds of all child objects, then setting the transform of the parent to the children. But this causes jittery behaviour since moving the parent also moves the children.
There are two ways of doing this, the best way is to change the structure following:
A (parent)
B (child 1)
C (child 2)
to:
Root (new parent with nothing on it)
A (old parent)
B (old child 1)
C (old child 2)
Then move A the way you tried before. You might also want to look into Joints, and see if this might suit your need better. If you don't want two colliders to interact with each other, you might also want to look into Layer Based Collision Detection and Physics.IgnoreCollision().
An alternative that I really wouldn't recommend, is counteracting the movement of the parent with the children. So whenever you move the parent you move the local position of the child you want to stay still the opposite amount. This however could possibly make your physics wonky.

Unity-child deforms when parent is rotated

Child changes geometry when i rotate the parent.
Parent is empty object and has scale (1, 1, 1).
Child is basic Capsule with adjusted rotation, position and scale.
I already tried deleting everything and i started over but nothing changed.
Please help me, thanks.

Rotate a body about a given point Unity2d

How to rotate a body relative to given dx dy in Unity? For example, I have a weapon sprite with a hand, and I was able to make it rotate relative to its center so that the weapon looks at the cursor, how can I rotate not relative to the center of the sprite, but relative to a given point?
The simplest way to achieve this is to set a gameobject at your desired point and make your object child of the created object. So when you rotate the parent, it will rotate relative to the parent point.
You can create an empty object and set the body as its child, then rotate the parent, the body will rotate around the parent like the parent be its pivot.
This is a practical way to set the pivot, and you can change it at any time.

Move a GameObject by its child objects

I wanted to create some evolution like "game". I make some bones, muscles, etc. When I hit play the creature moved but when I've checked the distance it stayed 0. What I've discovered was that all individual child elements moved but the containing GameObject was stil at the same position.
What is the (correct) way to make changes of a child object affect the parent object? Like moving legs to move the person.
The question seemed clear in my head but after reading your questions, remarks and comments I needed elaborate more:
I understand the basic idea of walking animations and such (i think). But here I'm trying to move a creature by itself. At first purely random movement and hopefully later on via a neural network.
In the sample screenshot below you see a creature, the spheres are colored for its weight and the beams between the spheres are the bone/muscle. And my creature limbs do move by pulsating the bone/muscles... but the position of the parent object stay the same. The magenta line is the position of the parent. I would like that the position of the parent would follow the center of its elements.
Your question is a bit unclear to what exactly it is you are after. However, if you want the child-parent behaviour become reveresed in a way that child becomes parent and parent becomes child just for function A() , you can simply swap the child and parents relation in A() itself,
As an example,
void A()
{
child.transform.SetParent(parent.transform.parent);
parent.transform.SetParent(child.transform);
... // your A function
parent.transform.SetParent(child.transform.parent);
child.transform.SetParent(parent.transfotm);
}

Unity Gameobject is far away from the Move Tool

why is my Gameobject so far away from the Move Tool as you can see in the Picture down below?
I would like to have it centered at the Gameobject. How can I change this?
GameObject away from Move Tool
Screenshot of Hierarchy
Check the object in the scene hierarchy and make sure that the transform eg. x,y,z are set to 0.
If your object is a child of another object and they are not at the same position you are probably moving the parent and not the child object itself.
that Move Tool is the objects origin, and this might help:
"The easiest way is to create an empty object as a parent object. Then you put the corridor object as a child of the empty object. You can then alter the position of the corridor object so its positioned at the edge.
i found your answer here
note that its not exact, in your case, make an empty object, move it to where you would like your origin or move tool THEN add your other object to it as a child. you can then move it with the parents move tool(origin) right on top of your box.