How to correctly move the parent object after the child?

I want to move a parent object while “holding” its child. I am trying to write a tool for Editor. Therefore, my script is marked with the [ExecuteInEditMode] attribute. But the attribute is only indirectly related to the question.

The direct solution is this:

public class MoveController : MonoBehavior
    [SerializeField] private Transform _child;

    private void Update()
        transform.position = _child.position;

It has been accepted as an answer here:

However, the last comment clearly describes the problem with a solution like this:

if we move the child … at a constant
speed … then the child will continue
to accelerate off screen

I’m moving the child element with the Move tool (“arrows”). But I get exactly the same result. Obviously, when the parent is moved, a new movement of the child also occurs. It is added to the original movement. This leads to a rapid and uncontrolled increase in the speed of movement.

I assumed that a offset is required. It must be taken into account when moving. A similar method has been discussed here: How to move parent when child moves? - Questions & Answers - Unity Discussions

But the accepted answer essentially leaves the parent in its place:

transform.parent.position = transform.position - transform.localpostion;

I thought I needed a local offset. I wrote this code:

private void Update()
    Vector3 delta = _child.localPosition - _oldChildLocalPosition;
    _child.position -= delta;
    transform.position += delta;

    _oldChildLocalPosition = _child.localPosition;

However, the result is about the same. The parent speeds up unpredictably when the child is moved. Did I make a stupid mistake somewhere? Or am I missing some important non-obvious detail?

You dont need to move the child if you want it to move with the parent, just move the parent the child is local to its parents space so will move with it automatically.

you have few solutions

  1. first move the gameobject that you want and when it came to desire destination make it the child of other gameobject
  2. move the parent itself and the child will move with it
  3. make one parent for both of your gameobjects now movement of the each gameobjects is not related to each other… let’s say for example you make one empty gameobject and put two in it as child now they are organize and related by that one empty gameobject (parent) and you could put a script attached to the empty gameobject and control every child in it but it’s not necessary cuz you can move the other children by one of the children in it also don’t forget at first reset the empty gameobject so it’s zero in everything

moving or rotating or scaling the parent without any effect on children if not possible but very hard and unnecessary act