Follow the the parent normally but without y and z axis ?

So here is my setup i have a parent and a child i want the child to follow the parent but not to follow the parent local z and y axis.

So lets say that the parent is at 0,0,0 and the child of that parent is at 0,0,1 and i started the game and lets say suddenly the parent moved forward, in this case the child well move forward too and stay at 0,0,1 and that is not what i want i want the parent to move forward and backwards and up and down without effecting the child but if the parent moves left and right i want the child to follow left and right also.

Would really love an answer for this problem and would like to know if there is a way without parenting.

btw i’m sorry if the question is to long i just wanted to be specific for everyone to understand.

in basic psudo code, with no parenting

var for followed object

update loop

transform.position = new vector 3 (other object.transform.pos.x , 0, 0);

done. - you could also go as far as to put a rigidbody on the following object and constrain movement on the y and z axis, but remember about the gravity and i’m not sure that would work with parenting.