- Home /
Update rotation from touch and drag
Hi everyone, I'm making a multiplayer 2D CirclePong game in Unity and have ran into an issue involving the racket controls.
I want the controls of the game to be so that if I drag and hold the white racket with my finger only the z axis rotation of the racket moves. Meaning as long as I hold the racket and move my finger in circles the racket would move along with finger always staying on a circular path. Please see the image to better understand the idea.
I really have no clue where to begin on this so if anyone could point me in the right direction that would be greatly appreciated.
Edit: This thread helped me out to solve this problem.
Answer by Mrintoxx · Aug 06, 2020 at 07:47 AM
You can use this to convert mouse position to a world point.
Vector3 worldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
And then associate de the worldPosition.x to the Gameobject rotation along the Z axis
someGameObject.Transform.rotation = new Vector3(0 , 0, worldPosition.x);
Hope it can help you