Unity3d 以特定角度向左或向右旋转游戏对象

Unity3d 以特定角度向左或向右旋转游戏对象,unity3d,rotation,unity5,Unity3d,Rotation,Unity5,所以基本上我想做的是,当我通过操纵杆移动我的角色时,我想计算角色旋转的当前角度和他应该旋转的新角度。例如:我将操纵杆移动到45度,因此我的角色向右旋转45度。现在我将操纵杆移动到90度。基本上,我想计算当前角度和新角度之间的差值,然后在特定角度旋转。在这种情况下,它将向左旋转45度,我的角色应该向左旋转45度 最好的方法是什么 void Update() { // move _rigidbody.MovePosition(transform.position + (tra

所以基本上我想做的是,当我通过操纵杆移动我的角色时,我想计算角色旋转的当前角度和他应该旋转的新角度。例如:我将操纵杆移动到45度,因此我的角色向右旋转45度。现在我将操纵杆移动到90度。基本上,我想计算当前角度和新角度之间的差值,然后在特定角度旋转。在这种情况下,它将向左旋转45度,我的角色应该向左旋转45度

最好的方法是什么

 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 from up right to up left : +0 to +180 and from down left to down right: -180 to -0

     //    double difference =....; here i want to calc the angle my char. should rotate 
     //    transform.Rotate(Vector3.up,(float)difference * Time.deltaTime);

     }

我认为一般公式应该是
diff=sensitivity*speed*deltaTime*deltaJoy
我认为一般公式应该是
diff=sensitivity*speed*deltaTime*deltaJoy