所以基本上我要做的是当我通过操纵杆移动我的角色时我想要计算角色旋转的当前角度以及他应该旋转的新角度。例如:我正在将操纵杆移动到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);
}