- Home /
Rotating Joystick on Touch
How can I make my Joystick rotate on touch?
For example:
When I touch the top part of the joystick, or drag the joystick upwards, the joystick rotates upwards.
And when I touch the bottom part of the joystick, or drag the joystick downwards, the joystick rotates downwards.
I'm finding this really hard to be honest. This was my original code that just doesn't work properly at all. When I touch a part of the screen, the object just keeps on rotating forever. I got this code from some tutorial.
if (Input.touchCount > 0) {
pitch -= Input.GetTouch(0).deltaPosition.y * 5 * Time.deltaTime;
yaw += Input.GetTouch(0).deltaPosition.x * 5 * Time.deltaTime;
//limit
pitch = Mathf.Clamp(pitch, -80, 80);
//do the rotations
transform.eulerAngles += new Vector3 ( 0, pitch, yaw);
}
The joystick is a 3D object with a collider though, not a GUITexture.
Also, how can I make it so that, it will only rotate when the player is touching the joystick?
The code I just posted above makes the object rotate wherever I touch on the screen.
Thanks!
Oh and just in case, I'm building this for the Android.
----------------------------------------------------------EDIT----------------------------------------------------------
It didn't work properly.
Your answer
Follow this Question
Related Questions
Rotating without gimbal lock 1 Answer
How to rotate an object without using a timer 1 Answer
Stopping rotation at 90° and -90°/270°. 0 Answers
Trouble with Vector3.Angle() and RotateAround() 1 Answer
Flip over an object (smooth transition) 3 Answers