How to make a child game object move based on the parent position ?

So i want to make the turret of a tank and a CHILD of it, go back and forth when shooting, so this is what i’ve done :

IEnumerator Gun1BackandForth()
    {
        // when i shoot i call this Coroutine to move the position 
        //of the tank on the y and then return it ( to tank position) :
         Vector3 position = Gun1Transform.position;
    position.y -= 0.1f;
    Gun1Transform.position = position;

    yield return new WaitForSeconds(0.05f);
  
    Gun1Transform.position = transform.position;

    }

it works great ! but when the tank is rotated, the turret keeps go DOWN, like it’s not a child of the tank, it does follow the tank but when shooting and reducing the y value, the turret goes down always. isn’t the turret suppesed to have new coordinations because it’s a child? please help !

childTargetToPosition= targetposition - child.position;

childTargetToPosition.y = 0;             //Assumption y position whichever you want to

parent.position = parent.position + childTargetToPosition;

The problem actually was in transform.position, this is the global transform, so i need to replace it by transform. localPosition instead. I hope this helps someone ! If you still a bit puzzled search for global and local positions !