One more question about touches

Hi,
I’m working on FPS game and there’s a crosshair(and it’s texture) on the screen. Now I need to move it with touch and drag. I have already searched through forums but nothing helps for me. Here’s my method:

protected void processMove(Vector3 delta)
	{
#if UNITY_ANDROID || UNITY_IPHONE
		if (Input.touchCount > 0)
		{
			if (Input.GetTouch(0).phase == TouchPhase.Began)
			{
				var t = Input.GetTouch(0);
				touchId = t.fingerId;
				startTouchPos = t.position;
			}

			var touch = Input.GetTouch(touchId);
			if(touch.phase == TouchPhase.Moved)
			{
				var x = touch.deltaPosition.x * Time.deltaTime * 10f;
				var y = touch.deltaPosition.y * Time.deltaTime * 10f;
				//var dest = Camera.main.ScreenToWorldPoint(
//new Vector3(startTouchPos.x, startTouchPos.y, 1000));

				crosshairPosition = new Rect(x, y, crosshairTexture.width, crosshairTexture.height);
			}
		}
#endif
	}

I’m calling this method in Update(). What am I doing wrong?

Thank you.

touch.deltaPosition is the delta from the last frame, not the delta from the first time the touch started. So you’re setting var x, y to roughly the same value every frame. I’m guessing that when you drag your finger faster, the crosshair moves a small amount and returns to center?

You instead probably want to use the difference from start:

var x = touch.position.x - startTouchPos.x;
var y = touch.position.y - startTouchPos.y;

I’m not sure why you would multiply by Time.deltaTime, so probably need to remove that.