I am trying to make a mobile game…
My problem is that it now moves on the x and y axis.
I only need the x axis, but I don’t know what to change to just move it on the x axis.
// Update is called once per frame
private void Update()
{
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
touchposition = Camera.main.ScreenToWorldPoint(touch.position);
touchposition.z = 0;
direction = (touchposition - transform.position);
rb.velocity = new Vector2(direction.x, direction.y) * movespeed;
if (touch.phase == TouchPhase.Ended)
rb.velocity = Vector2.zero;
}
}
}