unity3d - Rotate a gameobject in a specific angle left or right -


so trying when move character via joystick want calculate current angle character rotating , new angle in should rotate. example: moving joystick 45 degrees character rotating @ 45 degrees right. move joystick 90 degrees. want calculate difference between current , new angle , rotate @ specific angle. in case 45 degrees left , character should rotate 45 degrees left.

whats best way it?

 void update()  {      // move      _rigidbody.moveposition(transform.position + (transform.forward * leftcontroller.gettouchposition.y * time.deltatime * speedmovements) +          (transform.right * leftcontroller.gettouchposition.x * time.deltatime * speedmovements) );       if (myx != leftcontroller.gettouchposition.x || myy != leftcontroller.gettouchposition.y) { //checks if player changed position.          myx = leftcontroller.gettouchposition.x;          myy = leftcontroller.gettouchposition.y;           double rad = mathf.atan2(leftcontroller.gettouchposition.y, leftcontroller.gettouchposition.x); // in radians          double deg = rad * (180 / system.math.pi); // values right left : +0 +180 , down left down right: -180 -0       //    double difference =....; here want calc angle char. should rotate       //    transform.rotate(vector3.up,(float)difference * time.deltatime);       } 


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -