Question by
ersnbck · May 26, 2016 at 01:05 PM ·
unity 52d gamejoysticktouchscreen
How to rotate a 2d object with joystick in unity ?
In desktop version, my character's arm is rotates according to the movement of the mouse. I need the same thing in mobile version but this time I need a joystick to rotate his arm. How can I do that?
//Here is my code, for rotating arm
void Update()
{
Vector3 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
difference.Normalize();
float rotZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(0f, 0f, rotZ);
}
jborl.png
(52.2 kB)
Comment
Your answer
Follow this Question
Related Questions
how to fix automatic camera rotation when using joysticks? 0 Answers
Input.GetAxis("Vertical") not working on Mobile Phone 1 Answer
Object movement algorithm 0 Answers
Dash through enemies and dont taking damage 3 Answers
Joystick + swipe question? 0 Answers