1
\$\begingroup\$

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

This is what I want.enter image description here

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Waited more than I expected. I found a simple solution for this.

Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector2 direction = new Vector2(mousePos.x - transform.position.x, mousePos.y - transform.position.y
                );
transform.up = direction;
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .