I am creating a circular Joystick like setup in Unity. Played a lot with it in different ways but I don't get the desired results.
void Update()
{
//movement = Input.GetAxisRaw("Horizontal");
if (Input.touchCount > 0)
{
touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Began)
{
firstTouchY = touch.position.y;
}
if (touch.phase == TouchPhase.Moved)
{
if (touch.deltaPosition.y < 0)
{
movement = -1;
}
else if (touch.deltaPosition.y > 0)
{
movement = 1;
}
rotatePlayer();
}
}
}
private void rotatePlayer()
{
transform.RotateAround(Vector3.zero, Vector3.forward, movement * Time.fixedDeltaTime * moveSpeed);
}