hey i want to move ball left and right while ball is moving at a constant speed

now i have this code

transform.Translate(new Vector3(0f, 0f, speed));

@tanoshimi, i believe it’s with a mouse:

 // mouse x or y is -1 to 1
 
 float horizontalSpeed = 2.5f;
 float mouseH= horizontalSpeed * Input.GetAxis ("Mouse X");
 
 transform.Translate(new Vector3(mouseH, 0, speed);

use this :

var XP:float;

function Update()
{
	if (Input.touchCount > 0)
	{
		var touch = Input.GetTouch(0);
		if(touch.phase == TouchPhase.Began)
		{
			XP = touch.position.x;
		}
		if(touch.phase == TouchPhase.Moved)
		{
			if(touch.position.x < XP)
			{
				//Your Script That Make The Object Goes Right
			}
			else
			{
				//Your Script That Make The Object Goes Left
			}
		}
	}
}

XP mean where is finger in start touching ! if(touch.position.x < XP) check where is finger every frame !!! if finger is on right transform.Translate to right else transform.Translate to left :slight_smile: