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);
}
}
}