So I have a gameobject (my player) which moves via a joystick. Without the rotating code below my player moves well and smooth, but after I put the rotating code below the gameobject rotates all the time (360 degrees) when I try to move it.
My aim is to rotate the player in a given direction and stop when it’s done. I read that I should use RotateTowards but how can I do it when I have an angle. Or is there a better way to rotate it.
void Update()
{
// move
_rigidbody.MovePosition(transform.position + (transform.forward * leftController.GetTouchPosition.y * Time.deltaTime * speedMovements) +
(transform.right * leftController.GetTouchPosition.x * Time.deltaTime * speedMovements) );
//rotate
double rad = Mathf.Atan2(leftController.GetTouchPosition.y, leftController.GetTouchPosition.x); // In radians
double deg = rad * (180 / System.Math.PI);
transform.RotateAround(transform.position, Vector3.up , (float) deg *Time.deltaTime); //here it rotates all the time because of the frame
}