Move an object left and right while hinge joint attached

I have a game, in which the objects are spinning using a hinge joint, the problem with it is that i can move them left and right, my objects have no gravity and i need them to stay on a single y line. just to be able to move right and left + spin, I’ve tried to create a child for these objects to whom i attached the connected anchor, but due to no gravity its just floating around the map due to the spinning. this is my code if helps

rigidbody2D.gravityScale = 0;

		if (Input.touchCount > 0)
			var touch = Input.GetTouch(0);
			if (touch.position.x < Screen.width/2)
				transform.Translate(-Vector3.right * speed * Time.deltaTime);
			else if (touch.position.x > Screen.width/2)
				transform.Translate(Vector3.right * speed * Time.deltaTime);
		transform.position = new Vector3( Mathf.Clamp(transform.position.x, -3.65f, 3.65f), transform.position.y, transform.position.z);

attached both to my object and its child to move together with it

Well, I have a moving object using mouse movement. and the code is this

void Update () {
	Vector3 randomVarible = new Vector3 (0.5f, this.transform.position.y, 0f);
	float randomVarible = Input.mousePosition.x / Screen.width * 16;
	randomVarible.x = Mathf.Clamp(randomVarible, 0.5f, 15.5f);
	this.transform.position = randomVarible;

This is how I did it with mouse movement, maybe you can figure something out to do it with touch!

Lots and Lots of coding advice coming your way!