Multi Touch Drag Screen To Move Player?

Hello. it’s been a little while since I’ve last ask a question on here. I’ve been busy. Anyways I was messing around with touch controls and i was wondering if it’s possible to have multi touch controls, to where if I drag my finger to the left, the Player moves left, and if I drag it to the right, the Player moves right. I’ve seen people directly grab the object and drag it, but I don’t want to do that. I want to just drag the screen for the Player to move, and if I stop the Player will stop.

Right now my Player movements are set to the default arrow keys, so think of it as that. I also have a jump control to where you tap on any part of the screen and the Player jumps, so that’s why this needs to be multi touch or else it will affect the jump controls. By the way i’m testing controls so nothing is finalized yet, so feel free to suggest different ways of moving my Player. One way I already tried was virtual Joystick movement, I haven’t got it working yet. Anyways thanks for reading i hope you guys/gals can help.

Here’s a little part of my Character Controller script showing some things related to movement and jump:

public float defaultSpeed = 5f;
public float maxSpeed = 10f;
public float speed = 5f;

bool grounded = false;
public Transform groundCheck;
float groundRadius = 0.2f;
public LayerMask whatIsGround;
public float jumpForce = 700f;


void FixedUpdate ()
	{
		
		
		grounded = Physics2D.OverlapCircle (groundCheck.position, groundRadius, whatIsGround);
		anim.SetBool ("Ground", grounded);
		
		anim.SetFloat ("vSpeed", rigidbody2D.velocity.y);
		
		
		if (!grounded)
			return;

		float move = Input.GetAxis ("Horizontal");
		rigidbody2D.velocity = new Vector2 (move * maxSpeed, rigidbody2D.velocity.y);
		
		if (move > 0 && !facingRight)
			Flip ();
		else if (move < 0 && facingRight)
			Flip ();
		
	}
	
	void Flip()
	{
		facingRight = !facingRight;
		Vector3 theScale = transform.localScale;
		theScale.x *= -1;
		transform.localScale = theScale;
	}

	void Update()
	{
		if (grounded && Input.GetMouseButtonDown(0)) {
			anim.SetBool ("Ground", false);
			rigidbody2D.AddForce (new Vector2 (0, jumpForce));
			AudioSource.PlayClipAtPoint(JumpAudio[ Random.Range(0, JumpAudio.Length) ], transform.position, .6f);
		}
	}
}

Since you’re saying “multi touch” I’m assuming you mean two or more fingers.

What you’re looking for first then is Input.touchCount, which tells you how many fingers are currently touching the screen. Input.GetTouch(0) and Input.GetTouch(1) will give you the first two, and the deltaPosition property on each will give you the amount of movement. You can check Input.GetTouch(0).phase for the TouchPhase.Moved enum to verify that it actually HAS moved.

So a change you need to do to regular controls is to wrap it in a test for Input.touchCount == 1, for instance. Or a switch. Supporting three-finger special movement may also be useful.

With the new game controller support in iOS I think the second joystick on a typical gamepad would be the third and fourth joystick axis in the input options, but this is something I haven’t had the opportunity to play with.