1
votes

I am currently trying to implement a wheel shaped menu for an android game. The menu should rotate when the user moves his finger up or down the y axis of his screen.

Swipe up --> rotate counter clockwise

Swipe down --> rotate clockwise

I am able to rotate the menu via touch input, but the problem is the following: Every time the finger touches the display, the rotation is reset.

E.g. You can swipe up, the menu rotates and stays in place. But when you want to swipe up again to rotate even further, the rotation resets and starts over.

I guess the problem is very simple, but I tried a lot of stuff and nothing ever changes.

My code:

class{

    // ...

    void Update(){

        if(Input.touches.Length > 0 && Input.GetTouch(0).phase == TouchPhase.Moved){
                transform.rotation *= Quaternion.AngleAxis(Input.GetTouch(0).deltaPosition.y, Vector3.forward);
        }
    }
}

Thanks in advance!

1

1 Answers

1
votes

You need a variable to store the current rotation and simply add the change in angle each update.

public float angle;

void Update() {
    if ( Input.touches.Length > 0 && Input.GetTouch(0).phase == TouchPhase.Moved ) {
        angle += Input.GetTouch(0).deltaPosition.y;
        transform.rotation *= Quaternion.AngleAxis( angle, Vector3.forward );
    }
}