- Home /
Question by
PerfectClick · Jun 22, 2017 at 07:57 PM ·
unity 2djoystick
Moving Object Control by Joystick in unity2d
New in Unity ... in my case a player is moving while control by joystick.I wish that In which direction joystick clicked object should turn to that direction. i have lot of search on that but, i can't understand please help me with easy and understandable c# script. Thanks
float atan2 = Mathf.Atan2(CrossPlatformInputManager.GetAxis("Vertical"), CrossPlatformInputManager.GetAxis("Horizontal")) * Mathf.Rad2Deg ;
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(0, 0, (atan2 )), 5 * Time.deltaTime);
Vector3 pos = transform.position;
Vector3 velocity = new Vector3(0, maxSpeed * Time.deltaTime, 0);
pos += transform.rotation * velocity;
transform.position = pos;`
Comment